public Dictionary <string, RevitLinkProperties> CollectLinkInfo() { Dictionary <string, RevitLinkProperties> dictionary = new Dictionary <string, RevitLinkProperties>(); try { RevitLinkProperties rlp = new RevitLinkProperties(m_handler.ActiveDoc); if (!string.IsNullOrEmpty(rlp.IfcProjectGuid)) { dictionary.Add(rlp.IfcProjectGuid, rlp); } FilteredElementCollector collector = new FilteredElementCollector(m_handler.ActiveDoc); List <RevitLinkInstance> instances = collector.OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType().Cast <RevitLinkInstance>().ToList(); if (instances.Count > 0) { foreach (RevitLinkInstance instance in instances) { RevitLinkProperties p = new RevitLinkProperties(instance); if (null != p.LinkedDocument && !dictionary.ContainsKey(p.IfcProjectGuid)) { dictionary.Add(p.IfcProjectGuid, p); } } } } catch (Exception ex) { string message = ex.Message; } return(dictionary); }
/// <summary> /// Refresh components after selection of topic or viewpoint is changed /// </summary> public void RefreshComponents() { try { this.SelectedBCF = bcfView.BCFFiles[bcfView.SelectedIndex]; this.SelectedMarkup = selectedBCF.Markups[selectedBCF.SelectedMarkup]; ViewPoint selectedViewPoint = selectedMarkup.SelectedViewpoint; if (null != selectedViewPoint) { int viewpointInex = selectedMarkup.Viewpoints.IndexOf(selectedViewPoint); this.Comments = new ObservableCollection <Comment>(); this.SelectedComment = null; var commentFound = from comment in selectedMarkup.Comment where comment.Viewpoint.Guid == selectedViewPoint.Guid select comment; if (commentFound.Count() > 0) { this.Comments = new ObservableCollection <Comment>(commentFound.ToList()); this.SelectedComment = comments[0]; } if (null != selectedViewPoint.VisInfo) { this.SelectedComponent = null; this.SelectedComponentIndex = -1; this.RvtComponents.Clear(); var selectedProjects = from header in selectedMarkup.Header where linkDictionary.ContainsKey(header.IfcProject) select header.IfcProject; List <string> ifcProjectGuids = (selectedProjects.Count() > 0) ? selectedProjects.ToList() : linkDictionary.Keys.ToList(); ObservableCollection <Component> componentsToUpdate = new ObservableCollection <Component>(); foreach (Component comp in selectedViewPoint.VisInfo.Components) { int compIndex = selectedViewPoint.VisInfo.Components.IndexOf(comp); RevitComponent rvtComponent = null; if (!string.IsNullOrEmpty(comp.IfcGuid) && compDictionary.ContainsKey(comp.IfcGuid)) { RevitComponent sampleComp = compDictionary[comp.IfcGuid]; if (linkDictionary.ContainsKey(sampleComp.IfcProjectGuid)) { RevitLinkProperties rlp = linkDictionary[sampleComp.IfcProjectGuid]; Element compElement = rlp.LinkedDocument.GetElement(sampleComp.ElementId); if (null != compElement) { rvtComponent = new RevitComponent(comp, compElement, rlp); } } } if (null != rvtComponent) { var foundAction = from ext in selectedBCF.ExtensionColor.Extensions where ext.Guid == rvtComponent.Action.Guid select ext; if (foundAction.Count() > 0) { rvtComponent.Action = foundAction.First(); } var foundResponsibility = from ext in selectedBCF.ExtensionColor.Extensions where ext.Guid == rvtComponent.Responsibility.Guid select ext; if (foundResponsibility.Count() > 0) { rvtComponent.Responsibility = foundResponsibility.First(); } if (string.IsNullOrEmpty(comp.ElementName)) { componentsToUpdate.Add(comp); bcfView.BCFFiles[bcfView.SelectedIndex].Markups[selectedBCF.SelectedMarkup].Viewpoints[viewpointInex].VisInfo.Components[compIndex].ElementName = rvtComponent.ElementName; } this.RvtComponents.Add(rvtComponent); } } if (componentsToUpdate.Count > 0) { bool updatedDB = BCFDBWriter.BCFDBWriter.UpdateComponents(componentsToUpdate); } ApplyCategoryFilter(); UpdateBackgroundView(); } } } catch (Exception ex) { string message = ex.Message; } }