private void CollectElementMaps() { try { var hostDoc = Instance.Document; var categoryIds = Categories.Keys.ToList(); foreach (var catId in categoryIds) { var collector = new FilteredElementCollector(hostDoc); var elements = collector.OfCategoryId(catId).WhereElementIsNotElementType().ToElements().ToList(); var elementWithEntities = from element in elements where element.GetEntitySchemaGuids().Count > 0 select element; if (elementWithEntities.Count() > 0) { elements = elementWithEntities.ToList(); } foreach (var element in elements) { if (null == element.Location) { continue; } // unplaced rooms var linkInfo = MoverDataStorageUtil.GetLinkedElementInfo(element); if (null != linkInfo) { if (linkInfo.SourceLinkInstanceId != InstanceId) { continue; } if (element.Id != linkInfo.LinkedElementId) { continue; } var sourceElement = LinkedDocument.GetElement(linkInfo.SourceElementId); if (null != sourceElement) { linkInfo = new LinkedElementInfo(linkInfo.LinkElementType, sourceElement, element, InstanceId, TransformValue); if (!LinkedElements.ContainsKey(linkInfo.LinkedElementId)) { LinkedElements.Add(linkInfo.LinkedElementId, linkInfo); } } } } } } catch (Exception ex) { MessageBox.Show("Failed to collect element maps.\n" + ex.Message, "Collect Element Maps", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private bool UpdateModifiedElements(Document doc, List <ElementId> modifiedElementIds) { var updated = false; try { var linkedInstances = handler.LinkInstances; foreach (var elementId in modifiedElementIds) { var element = doc.GetElement(elementId); if (element.GetEntitySchemaGuids().Count > 0) { var linkInfo = MoverDataStorageUtil.GetLinkedElementInfo(element); if (null != linkInfo) { if (linkedInstances.ContainsKey(linkInfo.SourceLinkInstanceId)) { var lip = linkedInstances[linkInfo.SourceLinkInstanceId]; if (lip.LinkedElements.ContainsKey(linkInfo.LinkedElementId)) { var sourceElement = lip.LinkedDocument.GetElement(linkInfo.SourceElementId); if (null != sourceElement) { linkInfo.Matched = LinkedElementInfo.CompareLocation(sourceElement, element, lip.TransformValue); lip.LinkedElements.Remove(linkInfo.LinkedElementId); lip.LinkedElements.Add(linkInfo.LinkedElementId, linkInfo); linkedInstances.Remove(lip.InstanceId); linkedInstances.Add(lip.InstanceId, lip); } } } } } } handler.LinkInstances = linkedInstances; if (linkedInstances.ContainsKey(handler.SelectedLink.InstanceId)) { handler.SelectedLink = linkedInstances[handler.SelectedLink.InstanceId]; } handler.ApplyDocumentChanged(); } catch (Exception ex) { Log.AppendLog(LogMessageType.EXCEPTION, ex.Message); } return(updated); }