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 ControlledApplicationOnDocumentChanged(object sender, DocumentChangedEventArgs documentChangedEventArgs) { var doc = documentChangedEventArgs.GetDocument(); this.HandleDeletedElements(doc, documentChangedEventArgs.GetDeletedElementIds()); this.HandleChangedElements(doc, documentChangedEventArgs.GetModifiedElementIds()); }
/// <summary> /// DocumentChanged Handler /// </summary> /// <remarks> /// It monitors changes to the element that is being analyzed. /// If the element was changed, we ask it to restart the analysis. /// If the element was deleted, we ask the analyzer to stop. /// </remarks> /// public void DocChangedHandler(object sender, DocumentChangedEventArgs args) { if (m_analyzer != null) { // first we check if the element was deleted ICollection <ElementId> elems = args.GetDeletedElementIds(); if (elems.Contains(m_analyzer.AnalyzedElementId)) { m_analyzer.StopCalculation(); m_analyzer = null; // if we've stopped, we do not need events anymore UnsubscribeFromIdling(sender as UIApplication); UnsubscribeFromChanges(sender as UIApplication); } else // not deleted? what about changed? { elems = args.GetModifiedElementIds(); if (elems.Contains(m_analyzer.AnalyzedElementId)) { m_analyzer.RestartCalculation(); } } } else // no analyzer => no need for the events anymore { UnsubscribeFromIdling(sender as UIApplication); UnsubscribeFromChanges(sender as UIApplication); } }
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); } } }
public void ElementChangedEvent(object sender, DocumentChangedEventArgs args) { var elementFilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); var elementId = args.GetModifiedElementIds(elementFilter).First(); var nameTrans = args.GetTransactionNames().First(); TaskDialog.Show("Warning Changed", "Ban da thay doi doi tuong " + elementId + " Trans name la " + nameTrans); }
public void ElementChangedEvent(object sender, DocumentChangedEventArgs args) { ElementFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Furniture); ElementId elemId = args.GetModifiedElementIds(filter).First(); string name = args.GetTransactionNames().First(); TaskDialog.Show("Modified Element", $"{elemId.ToString()} changed by {name}"); }
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 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(dynRevitSettings.Doc.Document)) { processUpdates( args.GetModifiedElementIds(), args.GetDeletedElementIds(), args.GetAddedElementIds()); } }
internal void ControlledApplication_DocumentChanged(object sender, DocumentChangedEventArgs e) { Document doc = e.GetDocument(); ICollection <ElementId> modified = e.GetModifiedElementIds(); foreach (ElementId id in modified) { } }
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> /// 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; } }
/// <summary> /// Perform updates on in-canvas controls. /// In this example, the In-Canvas controls will be deleted, or have their positions changed, depending on the changes to related elements. /// </summary> /// <param name="data">Data about changes in the document.</param> public static void Execute(DocumentChangedEventArgs data) { Document doc = data.GetDocument(); TemporaryGraphicsManager temporaryGraphicsManager = TemporaryGraphicsManager.GetTemporaryGraphicsManager(doc); IssueMarkerTracking tracking = IssueMarkerTrackingManager.GetInstance().GetTracking(doc); foreach (ElementId deleted in data.GetDeletedElementIds()) { if (tracking.GetMarkerByElementId(deleted) is IssueMarker marker) { // This is how to delete control temporaryGraphicsManager.RemoveControl(marker.ControlIndex); // Don't forget to clean up your own data tracking.RemoveMarkerByElement(deleted); } } foreach (ElementId updated in data.GetModifiedElementIds()) { if (tracking.GetMarkerByElementId(updated) is IssueMarker marker) { Element element = doc.GetElement(updated); // Since we keep a copy of InCanvasControlData, we can avoid creating a new one. It already has image and position set - and we can just change the position InCanvasControlData controlData = marker.InCanvasControlData; if (element.Location is LocationPoint pointLoc) { controlData.Position = pointLoc.Point; } else if (element.Location is LocationCurve curveLoc) { controlData.Position = curveLoc.Curve.GetEndPoint(0); } marker.InCanvasControlData = controlData; // This is how to set updated data to a control temporaryGraphicsManager.UpdateControl(marker.ControlIndex, marker.InCanvasControlData); } } }
public static void OnDocumentChanged( object InSender, DocumentChangedEventArgs InArgs) { FDirectLink DirectLink = FDirectLink.Get(); Debug.Assert(DirectLink != null); // Handle modified elements foreach (ElementId ElemId in InArgs.GetModifiedElementIds()) { Element ModifiedElement = DirectLink.RootCache.SourceDocument.GetElement(ElemId); if (ModifiedElement.GetType() == typeof(RevitLinkInstance)) { DirectLink.ModifiedLinkedDocuments.Add((ModifiedElement as RevitLinkInstance).GetLinkDocument()); } DirectLink.RootCache.ModifiedElements.Add(ElemId); } }
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); } } } }
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(dynRevitSettings.Doc.Document)) { this.processUpdates( args.GetModifiedElementIds(), args.GetDeletedElementIds(), args.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 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()); }
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); } } } }
/// <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 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事件,并针对不同的绘制情况而进行不同的处理 /// </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); } } }
void OnDocumentChanged(object sender, DocumentChangedEventArgs args) { var elementDoc = args.GetDocument(); var modifiedElementsId = args.GetModifiedElementIds(); // Кэширование данных (маркеры изменения координат) ProjectLocation projectLocation = null; SiteLocation siteLocation = null; RevitLinkInstance rvtPositionProvider = null; ImportInstance dwgPositionProvider = null; foreach (var elementId in modifiedElementsId) { var element = elementDoc.GetElement(elementId); // Пропускаем элементы, не относящиеся к данному файлу if (element.Document.Title != Globals.ActiveDocumentTitle) { continue; } // Проверяем категорию изменённого элемента на принадлежность к маркерам изменения общих координат switch (element) { case ProjectLocation loc: projectLocation = loc.Document.ActiveProjectLocation; break; case RevitLinkInstance link: rvtPositionProvider = link; break; case ImportInstance link: dwgPositionProvider = link; break; case SiteLocation site: siteLocation = site; break; } } // Фильтруем события, не относящиеся к изменению площадок if (projectLocation == null) { return; } // ИВЕНТ ПРИНЯТИЯ КООРДИНАТ ИЗ СВЯЗИ if (siteLocation != null && (rvtPositionProvider != null || dwgPositionProvider != null)) { // не самый рабочий вариант, т.к. некрасивый и в случае с dwg - не предоставляет имя площадки провайдера var positionProviderName = dwgPositionProvider != null?dwgPositionProvider.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString() : rvtPositionProvider.Name; // Извлечение имени площадки файла-провайдера string extractedSiteName = null; var providerSiteName = positionProviderName.Split(':'); if (providerSiteName.Count() > 1) { var providerFileName = providerSiteName.Last().Trim(); var spaceIdx = providerFileName.IndexOf(" ", StringComparison.Ordinal) + 1; extractedSiteName = providerFileName.Substring(spaceIdx); } var logging = $"ProviderFileName: {positionProviderName}" + $"SiteName: {projectLocation.Name}" + $"ParentFile: {Globals.ActiveDocumentTitle}" + $"ProviderSiteName: {extractedSiteName}"; } // ИВЕНТ ИЗМЕНЕНИЯ КООРДИНАТ В ПРОЕКТЕ if (siteLocation == null) { var logging = $"ProviderFileName: {Globals.ActiveDocumentTitle}" + $"SiteName: {projectLocation.Name}" + $"ParentFile: {Globals.ActiveDocumentTitle}"; } }