public static IEnumerable <Revit.Elements.Element> FilterBySolidIntersection(Revit.Elements.Element[] elements, Autodesk.DesignScript.Geometry.Solid solid) { Document document = DocumentManager.Instance.CurrentDBDocument; // Convert Proto to Revit var unionSolid = DynamoToRevitBRep.ToRevitType(solid) as Autodesk.Revit.DB.Solid; // List of unwrapped Dynamo element Ids List <ElementId> elementIds = elements.Select(x => x.InternalElement.Id).ToList(); // Collect intersected elements var сollector = new FilteredElementCollector(document, elementIds); сollector.WherePasses(new ElementIntersectsSolidFilter(unionSolid)); var colectedElements = сollector.ToElements(); return(colectedElements.Select(x => x.ToDSType(true))); }
public static DynamoRevitElements.DirectShape CreateRevitMass(DynamoElements.Solid BuildingSolid, DynamoRevitElements.Category Category) { if (BuildingSolid == null) { throw new ArgumentNullException(nameof(BuildingSolid)); } var revitCategory = Document.Settings.Categories.get_Item(Category.Name); TransactionManager.Instance.EnsureInTransaction(Document); var revitBuilding = RevitElements.DirectShape.CreateElement(Document, revitCategory.Id); try { revitBuilding.SetShape(new[] { DynamoToRevitBRep.ToRevitType(BuildingSolid) }); } catch (Exception ex) { try { revitBuilding.SetShape(BuildingSolid.ToRevitType()); } catch { throw new ArgumentException(ex.Message); } } TransactionManager.Instance.TransactionTaskDone(); revitCategory.Dispose(); var directShape = revitBuilding.ToDSType(false) as DynamoRevitElements.DirectShape; revitBuilding.Dispose(); return(directShape); }
private static IList <GeometryObject> GenerateTessellatedGeo(DesignScriptEntity shapeReference, ElementId materialId) { IList <GeometryObject> tessellatedShape = null; if (shapeReference is Autodesk.DesignScript.Geometry.Mesh) { tessellatedShape = (shapeReference as Autodesk.DesignScript.Geometry.Mesh).ToRevitType( TessellatedShapeBuilderTarget.Mesh, TessellatedShapeBuilderFallback.Salvage, MaterialId: materialId); } else if (shapeReference is Autodesk.DesignScript.Geometry.Surface) { // Defer to tessellated shape if BRep shape for some reason fails GeometryObject geometry = null; try { geometry = DynamoToRevitBRep.ToRevitType(shapeReference as Autodesk.DesignScript.Geometry.Surface, true, materialId); } catch { } if (geometry != null) { tessellatedShape = new List <GeometryObject>() { geometry }; } else { tessellatedShape = (shapeReference as Autodesk.DesignScript.Geometry.Surface).ToRevitType(TessellatedShapeBuilderTarget.AnyGeometry, TessellatedShapeBuilderFallback.Mesh, MaterialId: materialId); } } else if (shapeReference is Autodesk.DesignScript.Geometry.Solid) { // Defer to tessellated shape if BRep shape for some reason fails GeometryObject geometry = null; try { geometry = DynamoToRevitBRep.ToRevitType(shapeReference as Autodesk.DesignScript.Geometry.Solid, true, materialId); } catch { } if (geometry != null) { tessellatedShape = new List <GeometryObject>() { geometry }; } else { tessellatedShape = (shapeReference as Autodesk.DesignScript.Geometry.Solid).ToRevitType(TessellatedShapeBuilderTarget.AnyGeometry, TessellatedShapeBuilderFallback.Mesh, MaterialId: materialId); } } if (tessellatedShape == null) { throw new ArgumentException(Revit.Properties.Resources.DirectShapeInvalidArgument); } return(tessellatedShape); }