void ApplicationDocumentChanged(object sender, DocumentChangedEventArgs args) { var doc = args.GetDocument(); var added = args.GetAddedElementIds().Select(x => doc.GetElement(x).UniqueId); var addedIds = args.GetAddedElementIds(); var modified = args.GetModifiedElementIds().Select(x => doc.GetElement(x).UniqueId).ToList(); var deleted = args.GetDeletedElementIds(); ProcessUpdates(doc, modified, deleted, added, addedIds); }
void OnDocumentChanged(object sender, DocumentChangedEventArgs e) { try { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; if (e.GetAddedElementIds().Count == 0 & e.GetModifiedElementIds().Count == 0) { return; } if (e.GetAddedElementIds().Count > 0) { Element myElement = doc.GetElement(e.GetAddedElementIds().First()); if (myElement.GetType().Name != "FamilyInstance") { return; } } if (e.GetModifiedElementIds().Count > 0) { Element myElement = doc.GetElement(e.GetModifiedElementIds().First()); if (myElement.GetType().Name != "FamilyInstance") { return; } } uidoc.Application.Application.DocumentChanged -= new EventHandler <DocumentChangedEventArgs>(OnDocumentChanged); SetForegroundWindow(uidoc.Application.MainWindowHandle); //this is an excape event keybd_event(0x1B, 0, 0, 0); keybd_event(0x1B, 0, 2, 0); keybd_event(0x1B, 0, 0, 0); keybd_event(0x1B, 0, 2, 0); } #region catch and finally catch (Exception ex) { _952_PRLoogleClassLibrary.DatabaseMethods.writeDebug("OnDocumentChanged" + Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException, true); } finally { } #endregion }
private void ElementCreated_AddToDictionary(object sender, DocumentChangedEventArgs e) { Document doc = e.GetDocument(); ICollection <ElementId> createdElements = e.GetAddedElementIds(); foreach (ElementId eid in createdElements) { Element ele = doc.GetElement(eid); try { int elementIdKey = eid.IntegerValue; if (ele.Category.Name != null) { string keyCategoryName = ele.Category.Name; dictionaryDB.Add(elementIdKey, keyCategoryName); } //System.IO.File.AppendAllText(@"C:\Temp\RevitDB.txt", String.Format("{0} : {1}\n",elementIdKey, keyCategoryName)); } catch { } } }
private void documentChangedEventFillingListOfElements(object sender, DocumentChangedEventArgs e) { //Null if the window is not open if (MainForm._changedElements == null) { return; } ElementClassFilter FamilyInstanceFilter = new ElementClassFilter(typeof(View), true); var addedElements = e.GetAddedElementIds(FamilyInstanceFilter); var deletedElements = e.GetDeletedElementIds(); var modifiedElements = e.GetModifiedElementIds(FamilyInstanceFilter); if (RevitManagement.changedElements == null) { RevitManagement.changedElements = new List <ElementId>(); } RevitManagement.changedElements.AddRange(addedElements); RevitManagement.changedElements.AddRange(modifiedElements); RevitManagement.deletedElements = deletedElements.ToList(); RevitManagement.changedElements = RevitManagement.changedElements.Distinct().ToList(); foreach (var item in RevitManagement.changedElements) { if (!MainForm._changedElements.Contains(item)) { MainForm.AddChangedItem(item); } } }
void OnDocumentChanged( object sender, DocumentChangedEventArgs e) { ICollection <ElementId> idsAdded = e.GetAddedElementIds(); int n = idsAdded.Count; Debug.Print("{0} id{1} added.", n, Util.PluralSuffix(n)); // This does not work, because the handler will // be called each time a new instance is added, // overwriting the previous ones recorded: //_added_element_ids = e.GetAddedElementIds(); _added_element_ids.AddRange(idsAdded); if (_place_one_single_instance_then_abort && 0 < n) { // Why do we send the WM_KEYDOWN message twice? // I tried sending it once only, and that does // not work. Maybe the proper thing to do would // be something like the Press.OneKey method... // //Press.OneKey( _revit_window.Handle, // (char) Keys.Escape ); // // Nope, that did not work. // // Answer: When you place instances with // PromptForFamilyInstancePlacement, the previous // one remains selected just until you drop the // next one. The first esc key hit removes that // selection while still allowing you to continue // adding instances to the model. Only a second // esc hit aborts the command. //Press.PostMessage( _revit_window.Handle, // (uint) Press.KEYBOARD_MSG.WM_KEYDOWN, // (uint) Keys.Escape, 0 ); // 2018 //Press.PostMessage( _revit_window.Handle, // (uint) Press.KEYBOARD_MSG.WM_KEYDOWN, // (uint) Keys.Escape, 0 ); // 2018 Press.PostMessage(_revit_window, (uint)Press.KEYBOARD_MSG.WM_KEYDOWN, (uint)Keys.Escape, 0); // 2019 Press.PostMessage(_revit_window, (uint)Press.KEYBOARD_MSG.WM_KEYDOWN, (uint)Keys.Escape, 0); // 2019 } }
private void OnDocumentChanged(object sender, DocumentChangedEventArgs e) { try{ setInfos(e); // get deleted elements ID if (e.Operation == UndoOperation.TransactionCommitted) { if (e.GetTransactionNames()[0] == "”далить выбранные" || e.GetTransactionNames()[0] == "Delete selection") { foreach (var item in e.GetDeletedElementIds()) { if (!addedList.Contains(item)) { deletedList.Add(new DeletedElement(item.IntegerValue.ToString(), documentName, username)); } } } else if (e.GetTransactionNames()[0] != "ќбновление рабочих наборов до последней версии из хранилища" && e.GetAddedElementIds().Count > 0) { addedList.AddRange(e.GetAddedElementIds().AsEnumerable()); } } // remove deleted elements if the transaction is rolled back else if (e.Operation == UndoOperation.TransactionUndone) { if (e.GetTransactionNames()[0] == "”далить выбранные" || e.GetTransactionNames()[0] == "Delete selection" && deletedList.Count > 0) { foreach (var item in e.GetAddedElementIds()) { try { var removeItem = deletedList.Where(x => x.Id == item.IntegerValue.ToString()).First(); deletedList.Remove(removeItem); } catch { } } } } } catch { } }
void ApplicationDocumentChanged(object sender, DocumentChangedEventArgs args) { var doc = args.GetDocument(); var addedIds = args.GetAddedElementIds(); var modified = args.GetModifiedElementIds(); var deleted = args.GetDeletedElementIds(); ProcessUpdates(doc, modified, deleted, addedIds, args.GetTransactionNames()); }
void OnDocumentChanged(object sender, DocumentChangedEventArgs e) { // this does not work, because the handler will // be called each time a new instance is added, // overwriting the previous ones recorded: // //_added_element_ids = e.GetAddedElementIds(); _added_element_ids.AddRange(e.GetAddedElementIds()); }
void Application_DocumentChanged(object sender, DocumentChangedEventArgs args) { if (args.GetDocument().Equals(dynRevitSettings.Doc.Document)) { processUpdates( args.GetModifiedElementIds(), args.GetDeletedElementIds(), args.GetAddedElementIds()); } }
void app_DocumentChanged( object sender, DocumentChangedEventArgs e) { if (null == _addedElementIds) { _addedElementIds = new List <ElementId>(); } _addedElementIds.Clear(); _addedElementIds.AddRange( e.GetAddedElementIds()); }
private void OnDocumentChanged(object sender, DocumentChangedEventArgs e) { var app = sender as Application; var ids = e.GetAddedElementIds(); foreach (var elementId in ids) { if (!addedIds.Contains(elementId)) { addedIds.Add(elementId); } } }
public void RevitDocumentChanged(object sender, DocumentChangedEventArgs args) { if (!IsShowEvent) { return; } // You can get the list of ids of element added/changed/modified. Document doc = args.GetDocument(); ICollection <ElementId> idsAdded = args.GetAddedElementIds(); ICollection <ElementId> idsDeleted = args.GetDeletedElementIds(); ICollection <ElementId> idsModified = args.GetModifiedElementIds(); //Add to parameter comment Element elem; // Put it in a string to show to the user. string msg = "Added: "; foreach (ElementId id in idsAdded) { elem = doc.GetElement(id); Parameter param = elem.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS); param.Set(DateTime.Today.ToString()); msg += id.IntegerValue.ToString() + " "; } msg += "\nDeleted: "; foreach (ElementId id in idsDeleted) { msg += id.IntegerValue.ToString() + " "; } msg += "\nModified: "; foreach (ElementId id in idsModified) { msg += id.IntegerValue.ToString() + " "; } // Show a message to a user. TaskDialogResult res = default(TaskDialogResult); res = TaskDialog.Show("Revit UI Labs - Event", msg, TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel); // If the user chooses to cancel, show no more event. if (res == TaskDialogResult.Cancel) { IsShowEvent = false; } }
/// <summary> /// 监控新生成的tempFi /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void OnDocumentChanged(object sender, DocumentChangedEventArgs e) { Document doc = e.GetDocument(); foreach (ElementId id in e.GetAddedElementIds()) { Element elem = doc.GetElement(id); if (elem is FamilyInstance && (elem as FamilyInstance).Symbol.FamilyName == "TempFi") { tempFi2 = elem as FamilyInstance; } } }
static void OnDocumentChanged(object sender, DocumentChangedEventArgs e) { Document doc = e.GetDocument(); View view = FindElevationView(doc, e.GetAddedElementIds()); if (null != view) { string msg = string.Format("You just create an" + "elevation view '{0}'. Are you" + "sure you want to do that? " + "Elevations don't show hidden line" + "detail, which makes them unsuitable" + "for core wall elevations etc.", view.Name); TaskDialog.Show("ElevationChecker", msg); } }
/// <summary> /// This is our event handler. Simply report the list of element ids which have been changed. /// </summary> public void UILabs_DocumentChanged(object sender, DocumentChangedEventArgs args) { if (!m_showEvent) { return; } // You can get the list of ids of element added/changed/modified. Document rvtdDoc = args.GetDocument(); ICollection <ElementId> idsAdded = args.GetAddedElementIds(); ICollection <ElementId> idsDeleted = args.GetDeletedElementIds(); ICollection <ElementId> idsModified = args.GetModifiedElementIds(); // Put it in a string to show to the user. string msg = "Added: "; foreach (ElementId id in idsAdded) { msg += id.IntegerValue.ToString() + " "; } msg += "\nDeleted: "; foreach (ElementId id in idsDeleted) { msg += id.IntegerValue.ToString() + " "; } msg += "\nModified: "; foreach (ElementId id in idsModified) { msg += id.IntegerValue.ToString() + " "; } // Show a message to a user. TaskDialogResult res = default(TaskDialogResult); res = TaskDialog.Show("Revit UI Labs - Event", msg, TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel); // If the user chooses to cancel, show no more event. if (res == TaskDialogResult.Cancel) { m_showEvent = false; } }
private void ElementCreated(object sender, DocumentChangedEventArgs e) { Document doc = e.GetDocument(); string createdElementsIds = ""; ICollection <ElementId> createdElements = e.GetAddedElementIds(); foreach (ElementId eid in createdElements) { string value = "not in dictionary"; dictionaryDB.TryGetValue(eid.IntegerValue, out value); createdElementsIds += String.Format("{0} : {1}\n", eid.IntegerValue, value); } m_MyDock.txtBoxCreated.Text = String.Format("{0} element(s) created: \n{1}", createdElements.Count, createdElementsIds); }
private void ViewCreated(object sender, DocumentChangedEventArgs e) { Document doc = e.GetDocument(); ICollection <ElementId> createdElements = e.GetAddedElementIds(); foreach (ElementId eid in createdElements) { Element ele = doc.GetElement(eid); if (ele.Category.Name == "Views") { viewToOpen = ele as View; m_MyDock.labelView.Text = String.Format("{0} {1}", ele.Name, eid.ToString()); } else { m_MyDock.labelView.Text = "-"; } } }
private void Application_DocumentChanged(object sender, DocumentChangedEventArgs e) { if (MainWindow != null) { _currentDocument = e.GetDocument(); var hasImports = false; var added = e.GetAddedElementIds(); var removed = e.GetDeletedElementIds(); if (added != null && added.Any()) { foreach (var elementId in added) { if (_currentDocument.GetElement(elementId) is CADLinkType) { hasImports = true; break; } } } if (removed != null && removed.Any() && _dwgImportManagerVm.DwgImportsItems.Any()) { foreach (var elementId in removed) { foreach (var dwgImportsItem in _dwgImportManagerVm.DwgImportsItems) { if (dwgImportsItem.Id.Equals(elementId)) { hasImports = true; break; } } } } if (hasImports) { SearchImportsAndBind(true); } } }
/// <summary> /// DocumentChanged event handler /// </summary> static void OnDocumentChanged( object sender, DocumentChangedEventArgs e) { Document doc = e.GetDocument(); // To avoid reacting to family import, // ignore family documents: if (doc.IsFamilyDocument) { View view = FindElevationView( doc, e.GetAddedElementIds()); if (null != view) { string msg = string.Format( "You just created an " + "elevation view '{0}'. Are you " + "sure you want to do that? " + "(Elevations don't show hidden line " + "detail, which makes them unsuitable " + "for core wall elevations etc.)", view.Name); TaskDialog.Show("ElevationChecker", msg); // Make sure we see this warning once only // Unsubscribing to the DocumentChanged event // inside the DocumentChanged event handler // causes a Revit message saying "Out of // memory." //doc.Application.DocumentChanged // -= new EventHandler<DocumentChangedEventArgs>( // OnDocumentChanged ); } } }
public void AppEvent_DocChangedEventHandler(object sender, DocumentChangedEventArgs args) { // this.uiApp.Idling -= Main.ActiveModelessForm.UIAppEvent_IdlingEventHandler; this.haltIdlingHandler = true; // Retrieve the addedElement Ids and deletedElement Ids ICollection <ElementId> addedElements = args.GetAddedElementIds(); ICollection <ElementId> deletedElements = args.GetDeletedElementIds(); // Update the dataController's cached elements this.dataController.AddToAllElements(addedElements.ToList()); this.dataController.RemoveFromAllElements(deletedElements.ToList()); this.dataController.SetMode(requestHandler.FilterBy, true); // Put up a request to update the TreeView requestHandler.AddRequest(Request.UpdateTreeView); this.haltIdlingHandler = false; // this.uiApp.Idling += Main.ActiveModelessForm.UIAppEvent_IdlingEventHandler; return; }
void OnDocumentChanged( object sender, DocumentChangedEventArgs e) { ICollection<ElementId> idsAdded = e.GetAddedElementIds(); int n = idsAdded.Count; Debug.Print( "{0} id{1} added.", n, Util.PluralSuffix( n ) ); // This does not work, because the handler will // be called each time a new instance is added, // overwriting the previous ones recorded: //_added_element_ids = e.GetAddedElementIds(); _added_element_ids.AddRange( idsAdded ); if( _place_one_single_instance_then_abort && 0 < n ) { // Why do we send the WM_KEYDOWN message twice? // I tried sending it once only, and that does // not work. Maybe the proper thing to do would // be something like the Press.OneKey method... // //Press.OneKey( _revit_window.Handle, // (char) Keys.Escape ); // // Nope, that did not work. // // Answer: When you place instances with // PromptForFamilyInstancePlacement, the previous // one remains selected just until you drop the // next one. The first esc key hit removes that // selection while still allowing you to continue // adding instances to the model. Only a second // esc hit aborts the command. Press.PostMessage( _revit_window.Handle, (uint) Press.KEYBOARD_MSG.WM_KEYDOWN, (uint) Keys.Escape, 0 ); Press.PostMessage( _revit_window.Handle, (uint) Press.KEYBOARD_MSG.WM_KEYDOWN, (uint) Keys.Escape, 0 ); } }
/// <summary> /// Обработка события DocumentChanged /// </summary> private void OnDocumentChanged(object sender, DocumentChangedEventArgs e) { Document doc = e.GetDocument(); View view = FindElevationView( doc, e.GetAddedElementIds()); if (null != view) { string msg = string.Format( "Вы только что создали новый вид Фасад " + " '{0}'.", view.Name); TaskDialog.Show("ElevationChecker", msg); } }
void OnDocumentChanged(object sender, DocumentChangedEventArgs e) { _added_element_ids.AddRange(e.GetAddedElementIds()); }
private void OnDocumentChanged(object sender, DocumentChangedEventArgs e) { if (Committing) { return; } var document = e.GetDocument(); if (!document.Equals(ActiveDBDocument)) { return; } CancelReadActions(); var added = e.GetAddedElementIds(); var deleted = e.GetDeletedElementIds(); var modified = e.GetModifiedElementIds(); if (added.Count > 0 || deleted.Count > 0 || modified.Count > 0) { var materialsChanged = modified.Select((x) => document.GetElement(x)).OfType <Material>().Any(); foreach (GH_Document definition in Grasshopper.Instances.DocumentServer) { foreach (var obj in definition.Objects) { if (obj is IGH_Param param) { if (param.SourceCount > 0) { continue; } if (param.Phase == GH_SolutionPhase.Blank) { continue; } if (obj is GH.Parameters.IGH_PersistentGeometryParam persistent) { if (persistent.NeedsToBeExpired(document, added, deleted, modified)) { param.ExpireSolution(false); } } } else if (obj is IGH_Component component) { if (component is GH.Components.DocumentElements) { component.ExpireSolution(false); } else { bool needsToBeExpired = false; foreach (var inputParam in component.Params.Input) { if (inputParam.SourceCount > 0) { continue; } if (inputParam.Phase == GH_SolutionPhase.Blank) { continue; } if (inputParam is GH.Parameters.IGH_PersistentGeometryParam persistent) { if (persistent.NeedsToBeExpired(document, added, deleted, modified)) { needsToBeExpired = true; break; } } } if (needsToBeExpired) { component.ExpireSolution(true); } else { foreach (var outParam in component.Params.Output) { if (outParam is GH.Parameters.IGH_PersistentGeometryParam persistent) { if (persistent.NeedsToBeExpired(document, added, deleted, modified)) { foreach (var r in outParam.Recipients) { r.ExpireSolution(false); } } else if (materialsChanged) { foreach (var goo in outParam.VolatileData.AllData(true)) { if (goo is IGH_PreviewMeshData previewMeshData) { previewMeshData.DestroyPreviewMeshes(); } } } } } } } } } if (definition.Enabled) { definition.NewSolution(false); } } } }
void OnDocumentChanged( object sender, DocumentChangedEventArgs e) { // this does not work, because the handler will // be called each time a new instance is added, // overwriting the previous ones recorded: //_added_element_ids = e.GetAddedElementIds(); _added_element_ids.AddRange( e.GetAddedElementIds() ); }
/// <summary> /// The OnDocumentChanged: Update list revit element in model /// </summary> /// <param name="sender">The sender<see cref="object"/></param> /// <param name="args">The args<see cref="DocumentChangedEventArgs"/></param> private void OnDocumentChanged(object sender, DocumentChangedEventArgs args) { Document doc = args.GetDocument(); if (ModelProvider.Instance.CurrentModel == null || ModelProvider.Instance.DicRevitElements == null) { return; } if (doc.Title == ModelProvider.Instance.CurrentModel.Title) { List <ElementId> elementIds = new List <ElementId>(); foreach (ElementId id in args.GetAddedElementIds()) { Element e = doc.GetElement(id); if (null != e.Category && 0 < e.Parameters.Size && (e.Category.HasMaterialQuantities)) { RevitElement revitElement = new RevitElement(e); if (ModelProvider.Instance.DicRevitElements.ContainsKey(e.UniqueId)) { ModelProvider.Instance.DicRevitElements.Remove(e.UniqueId); ModelProvider.Instance.DicRevitElements.Add(e.UniqueId, revitElement); } else { ModelProvider.Instance.DicRevitElements.Add(e.UniqueId, revitElement); } } } foreach (ElementId id in args.GetDeletedElementIds()) { foreach (RevitElement item in ModelProvider.Instance.DicRevitElements.Values) { if (item.elementId == id.ToString()) { ModelProvider.Instance.DicRevitElements.Remove(item.guid); break; } } } foreach (ElementId id in args.GetModifiedElementIds()) { Element e = doc.GetElement(id); if (null != e.Category && 0 < e.Parameters.Size && (e.Category.HasMaterialQuantities)) { RevitElement revitElement = new RevitElement(e); if (ModelProvider.Instance.DicRevitElements.ContainsKey(e.UniqueId)) { ModelProvider.Instance.DicRevitElements.Remove(e.UniqueId); ModelProvider.Instance.DicRevitElements.Add(e.UniqueId, revitElement); } } } } }
void ApplicationDocumentChanged(object sender, DocumentChangedEventArgs args) { var doc = args.GetDocument(); var added = args.GetAddedElementIds().Select(x => doc.GetElement(x).UniqueId); var addedIds = args.GetAddedElementIds(); var modified = args.GetModifiedElementIds().Select(x => doc.GetElement(x).UniqueId).ToList(); var deleted = args.GetDeletedElementIds(); ProcessUpdates(doc, modified, deleted, added, addedIds); }
void Application_DocumentChanged(object sender, DocumentChangedEventArgs args) { if (args.GetDocument().Equals(DocumentManager.Instance.CurrentUIDocument.Document)) { processUpdates( args.GetModifiedElementIds(), args.GetDeletedElementIds(), args.GetAddedElementIds()); } }
void Application_DocumentChanged(object sender, DocumentChangedEventArgs args) { var doc = args.GetDocument(); ProcessUpdates( args.GetModifiedElementIds().Select(x => doc.GetElement(x).UniqueId).ToList(), args.GetDeletedElementIds().Select(x => doc.GetElement(x).UniqueId).ToList(), args.GetAddedElementIds().Select(x => doc.GetElement(x).UniqueId).ToList()); }
public void GetElementAdded(object sender, DocumentChangedEventArgs args) { ICollection <ElementId> elementIds = args.GetAddedElementIds(); TaskDialog.Show("so luong element duoc add them", elementIds.Count.ToString()); }
private void OnDocumentChanged(object sender, DocumentChangedEventArgs e) { NewElements.AddRange(e.GetAddedElementIds()); }
static void OnDocumentChanged(object sender, DocumentChangedEventArgs e) { var document = e.GetDocument(); var added = e.GetAddedElementIds(); var deleted = e.GetDeletedElementIds(); var modified = e.GetModifiedElementIds(); if (added.Count > 0 || deleted.Count > 0 || modified.Count > 0) { var materialsChanged = modified.Select((x) => document.GetElement(x)).OfType <Material>().Any(); foreach (GH_Document definition in Instances.DocumentServer) { bool expireNow = definition.SolutionState == GH_ProcessStep.PreProcess && Instances.ActiveCanvas.Document == definition; foreach (var obj in definition.Objects) { if (obj is IGH_Param param) { if (param.SourceCount > 0) { continue; } if (param.Phase == GH_SolutionPhase.Blank) { continue; } if (obj is Parameters.IGH_PersistentGeometryParam persistent) { if (persistent.NeedsToBeExpired(document, added, deleted, modified)) { if (expireNow) { param.ExpireSolution(false); } else { param.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "This parameter contains expired elements."); } } } } else if (obj is IGH_Component component) { if (component is Components.DocumentElements) { if (expireNow) { component.ExpireSolution(false); } else { component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Document has been changed since the last solution."); } } else { bool needsToBeExpired = false; foreach (var inputParam in component.Params.Input) { if (inputParam.SourceCount > 0) { continue; } if (inputParam.Phase == GH_SolutionPhase.Blank) { continue; } if (inputParam is Parameters.IGH_PersistentGeometryParam persistent) { if (persistent.NeedsToBeExpired(document, added, deleted, modified)) { needsToBeExpired = true; break; } } } if (needsToBeExpired) { if (expireNow) { component.ExpireSolution(false); } else { component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Some input parameter contains expired elements."); } } } } } if (expireNow && definition.Enabled) { definition.NewSolution(false); } } } }
/// <summary> /// DocumentChanged事件,并针对不同的绘制情况而进行不同的处理 /// </summary> /// <param name="sender">Application对象</param> /// <param name="e"></param> private void app_DocumentChanged(object sender, DocumentChangedEventArgs e) { if (e.Operation == UndoOperation.TransactionCommitted || e.Operation == UndoOperation.TransactionUndone || e.Operation == UndoOperation.TransactionRedone) { doc = e.GetDocument(); bool blnContinueDraw = false; // 在检查连续性后是否要继续绘制 try { // 先考察添加的对象:如果添加了新对象,则要么是 DrawNewLines ,要么是 DrawOtherObjects int addedCount = 0; Element addedElement = default(Element); foreach (ElementId eid in e.GetAddedElementIds()) { addedElement = doc.GetElement(eid); if (addedElement is ModelCurve) { AddedModelCurvesId.Add(eid); addedCount++; } } if (addedCount > 0) // 说明绘制了新的模型线 { // 检测当前集合中的曲线是否符合指定的连续性要求 if (this.CheckInTime) { CurvesState cs = ValidateCurves(AddedModelCurvesId, out blnContinueDraw); RefreshUiAfterValidation(cs, blnContinueDraw); } else // 说明不进行实时检测,而直接继续绘制 { } // return; } // // 再考察删除对象的情况 List <ElementId> deleted = e.GetDeletedElementIds().ToList(); if (deleted.Count > 0) { // 先将被删除的曲线从曲线链集合中剔除掉 int id_Chain = 0; // 曲线链中的元素下标 int id_deleted = 0; // 删除的模型线集合中的元素下标 for (id_Chain = AddedModelCurvesId.Count - 1; id_Chain >= 0; id_Chain--) // 曲线链中的元素下标 { // id_deleted = deleted.IndexOf(AddedModelCurvesId[id_Chain]); // 找到对应的项 // if (id_deleted >= 0) { deleted.RemoveAt(id_deleted); AddedModelCurvesId.RemoveAt(id_Chain); } } // 检测剔除后的集合中的曲线是否符合指定的连续性要求 if (this.CheckInTime) { if (this.CheckInTime) { CurvesState cs = ValidateCurves(AddedModelCurvesId, out blnContinueDraw); RefreshUiAfterValidation(cs, blnContinueDraw); } else // 说明不进行实时检测,而直接继续绘制 { } } else // 说明不进行实时检测,而直接继续绘制 { } // return; } // 再考察修改对象的情况(因为在添加对象或者删除对象时,都有可能伴随有修改对象):在没有添加新对象,只作了修改的情况下,要么是对 int modifiedCount = 0; Element modifiedCountElement = default(Element); foreach (ElementId eid in e.GetModifiedElementIds()) { modifiedCountElement = doc.GetElement(eid); if (modifiedCountElement is ModelCurve) { modifiedCount++; } } if (modifiedCount > 0) { // 检测剔除后的集合中的曲线是否符合指定的连续性要求 if (this.CheckInTime) { CurvesState cs = ValidateCurves(AddedModelCurvesId, out blnContinueDraw); RefreshUiAfterValidation(cs, blnContinueDraw); } else // 说明不进行实时检测,而直接继续绘制 { } // return; } } catch (Exception ex) { MessageBox.Show("在绘制模型线及连续性判断时出问题啦~~~" + "\r\n" + ex.Message + ex.GetType().FullName + "\r\n" + ex.StackTrace); // 结束绘制 this.FinishOnce(false, false); } } }
private void OnDocumentChanged(object sender, DocumentChangedEventArgs e) { var App = sender as Application; try { var docsInApp = App.Documents.Cast <Document>(); var ActiveDoc = e.GetDocument(); ids_add = e.GetAddedElementIds(); if (ids_add.Count != 1) { return; } var modelline = ids_add.First().GetElement(ActiveDoc) as ModelLine; var line = modelline.GeometryCurve as Line; //MessageBox.Show(line.Length.ToString()); var linedir = line.Direction; var startpo = line.StartPoint(); var endpo = line.EndPoint(); var updir = XYZ.BasisZ; var leftNorm = updir.CrossProduct(linedir).Normalize(); var rightNorm = updir.CrossProduct(-linedir).Normalize(); var leftspacePlane = default(Plane); //Plane.CreateByNormalAndOrigin(leftNorm, startpo); var rightspacePlane = default(Plane); //PPlane.CreateByNormalAndOrigin(rightNorm, startpo); #if Revit2016 leftspacePlane = new Plane(leftNorm, startpo); rightspacePlane = new Plane(rightNorm, startpo); #endif #if Revit2019 leftspacePlane = Plane.CreateByNormalAndOrigin(leftNorm, startpo); rightspacePlane = Plane.CreateByNormalAndOrigin(rightNorm, startpo); #endif var slapshapeEditor = floor.SlabShapeEditor; //剪切楼板 //var verticals = slapshapeEditor.SlabShapeVertices.Cast<XYZ>(); //var upfaceRef = HostObjectUtils.GetTopFaces(floor); //var upface = floor.GetGeometryObjectFromReference(upfaceRef.FirstOrDefault()); var geoele = floor.get_Geometry(new Options() { ComputeReferences = true, DetailLevel = ViewDetailLevel.Fine }); var solid = geoele.Getsolids().FirstOrDefault(); var newsolid1 = BooleanOperationsUtils.CutWithHalfSpace(solid, leftspacePlane); var newsolid2 = BooleanOperationsUtils.CutWithHalfSpace(solid, rightspacePlane); var upface1 = newsolid1.GetFacesOfGeometryObject().Where(m => m.ComputeNormal(new UV()).IsSameDirection(XYZ.BasisZ)) .FirstOrDefault(); var upface2 = newsolid2.GetFacesOfGeometryObject().Where(m => m.ComputeNormal(new UV()) == XYZ.BasisZ) .FirstOrDefault(); var curveloop1 = upface1.GetEdgesAsCurveLoops().FirstOrDefault(); var curvearray = curveloop1.ToCurveArray(); ActiveDoc.Invoke(m => { var newfloor1 = ActiveDoc.Create.NewFloor(curvearray, floor.FloorType, floor.LevelId.GetElement(ActiveDoc) as Level, false); }, "newfloor"); //var newfloor2 = // ActiveDoc.Create.NewFloor(, floor.FloorType, floor.LevelId.GetElement(ActiveDoc) as Level, false); //slapshapeEditor.DrawSplitLine() if (this != null) { App.DocumentChanged -= OnDocumentChanged; } } catch (Exception e1) { MessageBox.Show(e1.ToString()); App.DocumentChanged -= OnDocumentChanged; } }
void OnDocumentChanged( object sender, DocumentChangedEventArgs e) { _added_element_ids.AddRange( e.GetAddedElementIds() ); }
/// <summary> /// This is our event handler. Simply report the list of element ids which have been changed. /// </summary> public void UILabs_DocumentChanged(object sender, DocumentChangedEventArgs args) { if (!m_showEvent) return; // You can get the list of ids of element added/changed/modified. Document rvtdDoc = args.GetDocument(); ICollection<ElementId> idsAdded = args.GetAddedElementIds(); ICollection<ElementId> idsDeleted = args.GetDeletedElementIds(); ICollection<ElementId> idsModified = args.GetModifiedElementIds(); // Put it in a string to show to the user. string msg = "Added: "; foreach (ElementId id in idsAdded) { msg += id.IntegerValue.ToString() + " "; } msg += "\nDeleted: "; foreach (ElementId id in idsDeleted) { msg += id.IntegerValue.ToString() + " "; } msg += "\nModified: "; foreach (ElementId id in idsModified) { msg += id.IntegerValue.ToString() + " "; } // Show a message to a user. TaskDialogResult res = default(TaskDialogResult); res = TaskDialog.Show("Revit UI Labs - Event", msg, TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel); // If the user chooses to cancel, show no more event. if (res == TaskDialogResult.Cancel) { m_showEvent = false; } }
void app_DocumentChanged( object sender, DocumentChangedEventArgs e) { if( null == _addedElementIds ) { _addedElementIds = new List<ElementId>(); } _addedElementIds.Clear(); _addedElementIds.AddRange( e.GetAddedElementIds() ); }
void Application_DocumentChanged(object sender, DocumentChangedEventArgs args) { if (args.GetDocument().Equals(dynRevitSettings.Doc.Document)) { this.processUpdates( args.GetModifiedElementIds(), args.GetDeletedElementIds(), args.GetAddedElementIds() ); } }
void OnDocumentChanged(object sender, DocumentChangedEventArgs e) { var document = e.GetDocument(); var added = e.GetAddedElementIds(); var deleted = e.GetDeletedElementIds(); var modified = e.GetModifiedElementIds(); if (added.Count > 0 || deleted.Count > 0 || modified.Count > 0) { foreach (GH_Document definition in Instances.DocumentServer) { bool expireNow = (e.Operation == UndoOperation.TransactionCommitted || e.Operation == UndoOperation.TransactionUndone || e.Operation == UndoOperation.TransactionRedone) && GH_Document.EnableSolutions && Instances.ActiveCanvas.Document == definition && definition.Enabled && definition.SolutionState != GH_ProcessStep.Process; var change = new DocumentChangedEvent() { Operation = e.Operation, Document = document, Definition = definition }; foreach (var obj in definition.Objects) { if (obj is Parameters.IGH_ElementIdParam persistentParam) { if (persistentParam.DataType == GH_ParamData.remote) { continue; } if (persistentParam.Phase == GH_SolutionPhase.Blank) { continue; } if (persistentParam.NeedsToBeExpired(document, added, deleted, modified)) { if (expireNow) { persistentParam.ExpireSolution(false); } else { change.ExpiredObjects.Add(persistentParam); } } } else if (obj is Components.IGH_ElementIdComponent persistentComponent) { if (persistentComponent.NeedsToBeExpired(e)) { if (expireNow) { persistentComponent.ExpireSolution(false); } else { change.ExpiredObjects.Add(persistentComponent); } } } } if (definition.SolutionState != GH_ProcessStep.Process) { changeQuque.Enqueue(change); } else if (definition == Instances.ActiveCanvas.Document) { if (change.ExpiredObjects.Count > 0) { foreach (var obj in change.ExpiredObjects) { obj.ClearData(); obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"This object was expired because it contained obsolete Revit elements."); } Instances.DocumentEditor.SetStatusBarEvent ( new GH_RuntimeMessage ( change.ExpiredObjects.Count == 1 ? $"An object was expired because it contained obsolete Revit elements." : $"{change.ExpiredObjects.Count} objects were expired because them contained obsolete Revit elements.", GH_RuntimeMessageLevel.Remark, "Document" ) ); } } } } }
/// <summary> /// DocumentChanged event handler /// </summary> static void OnDocumentChanged( object sender, DocumentChangedEventArgs e) { Document doc = e.GetDocument(); // To avoid reacting to family import, // ignore family documents: if( doc.IsFamilyDocument ) { View view = FindElevationView( doc, e.GetAddedElementIds() ); if( null != view ) { string msg = string.Format( "You just created an " + "elevation view '{0}'. Are you " + "sure you want to do that? " + "(Elevations don't show hidden line " + "detail, which makes them unsuitable " + "for core wall elevations etc.)", view.Name ); TaskDialog.Show( "ElevationChecker", msg ); // Make sure we see this warning once only // Unsubscribing to the DocumentChanged event // inside the DocumentChanged event handler // causes a Revit message saying "Out of // memory." //doc.Application.DocumentChanged // -= new EventHandler<DocumentChangedEventArgs>( // OnDocumentChanged ); } } }
private void OnDocumentChanged(object sender, DocumentChangedEventArgs e) { Messenger.Default.Send(new DocumentChanged(e.GetDeletedElementIds(), e.GetAddedElementIds(), e.GetDocument())); }