public static void Focus(ClashItems elements) { View activeView = RevitTools.Doc.ActiveView; ResetView(); var listOfId = new List <ElementId>(); listOfId.Add(elements.ElementA.Id); if (elements.ElementB.Document.PathName == Doc.PathName) { listOfId.Add(elements.ElementB.Id); } RevitTools.Uidoc.Selection.SetElementIds(listOfId); RevitTools.Uidoc.ShowElements(listOfId); }
public static void IsolateSelectionTemporary(ClashItems clashItems) { CreateBox(clashItems); ICollection <ElementId> selectedIds = new List <ElementId>(); selectedIds.Add(clashItems.ElementA.Id); if (selectedIds.Count > 0) { try { //If element is in a link, add to list of selected elements if (clashItems.ElementB.Document.PathName != Doc.PathName) { RevitTools.Uidoc.ShowElements(selectedIds); var linkInstance = new FilteredElementCollector(Doc) .OfClass(typeof(RevitLinkInstance)) .ToElements() .Where(x => x.Name.Contains(clashItems.ElementB.Document.Title)).FirstOrDefault(); if (linkInstance != null) { selectedIds.Add(linkInstance.Id); } RevitTools.Doc.ActiveView.IsolateElementsTemporary(selectedIds); RevitTools.Uidoc.RefreshActiveView(); } else { selectedIds.Add(clashItems.ElementB.Id); RevitTools.Doc.ActiveView.IsolateElementsTemporary(selectedIds); RevitTools.Uidoc.ShowElements(selectedIds); RevitTools.Uidoc.RefreshActiveView(); } } catch (Exception vEx) { } } }
public static void CreateBox(ClashItems elements) { View3D activeView = (View3D)RevitTools.Doc.ActiveView; BoundingBoxXYZ A = elements.ElementA.get_BoundingBox(activeView); BoundingBoxXYZ B = elements.ElementB.get_BoundingBox(activeView); var XMax = Math.Max(A.Max.X, B.Max.X); var YMax = Math.Max(A.Max.Y, B.Max.Y); var ZMax = Math.Max(A.Max.Z, B.Max.Z); var XMin = Math.Min(A.Min.X, B.Min.X); var YMin = Math.Min(A.Min.Y, B.Min.Y); var ZMin = Math.Min(A.Min.Z, B.Min.Z); BoundingBoxXYZ bbx = new BoundingBoxXYZ() { Max = new XYZ(XMax, YMax, ZMax), Min = new XYZ(XMin, YMin, ZMin) }; activeView.SetSectionBox(bbx); }
public static List <ClashItems> clashingElements(Document doc, Application app, Document link = null) { var linkedElements = new List <Element>(); var localElements = new List <Element>(); var ClashingElementsA = new List <Element>(); var ClashingElementsB = new List <Element>(); //If second document was not provided, use first doc var SecondDocument = FormTools.linkedDocument == null ? doc : FormTools.linkedDocument; //Get the transformation of the linked model from the project location var transform = GetTransform(doc, SecondDocument); Autodesk.Revit.DB.Options opt = new Options(); var ActiveViewBB = doc.ActiveView as View3D; //Hard coded selection LogicalOrFilter filterLinkedCategories = new LogicalOrFilter(FormTools.SelectedCategories); FilteredElementCollector collector = new FilteredElementCollector(SecondDocument).WherePasses(filterLinkedCategories).WhereElementIsNotElementType(); linkedElements = collector.ToElements() as List <Element>; var ClashItemsList = new List <ClashItems>(); foreach (Element elementB in linkedElements) { GeometryElement geom = elementB.get_Geometry(opt); GeometryElement geomTranslated = geom; // Get bounding box from transformed geometry // By default use element geometry to extract bbox var bbox = geom.GetBoundingBox(); if (transform != null) { //If translation is valid, use it to override the bbox geomTranslated = geom.GetTransformed(transform); bbox = geomTranslated.GetBoundingBox(); } if (belongsToView(ActiveViewBB, bbox)) { //VisibleLinkedElements.Add(geomTranslated); Outline outline = new Outline(bbox.Min, bbox.Max); BoundingBoxIntersectsFilter bbFilter = new BoundingBoxIntersectsFilter(outline); LogicalOrFilter logicalOrFilter = new LogicalOrFilter(FormTools.SelectedHostCategories); FilteredElementCollector bbClashingCollector = new FilteredElementCollector(doc, doc.ActiveView.Id).WherePasses(logicalOrFilter).WherePasses(bbFilter); foreach (Element elementA in bbClashingCollector.ToElements()) { if (!ClashingElementsA.Contains(elementA)) { if (getClashWithSolid(doc, geomTranslated, elementA) && elementA.Id != elementB.Id && !ClashItemsList.Any(x => (x.ElementA.Id == elementB.Id && x.ElementB.Id == elementA.Id)) ) { ClashItems clashItems = new ClashItems { ElementA = elementA, ElementB = elementB }; ClashItemsList.Add(clashItems); } } } } } return(ClashItemsList); }