public static List <Polygon3D> ToSAM_Polygon3Ds(this Autodesk.Revit.DB.Face face, double tolerance = Core.Tolerance.Distance) { if (face == null) { return(null); } if (face is PlanarFace) { return(ToSAM_Polygon3Ds((PlanarFace)face, tolerance)); } List <Polygon3D> result = new List <Polygon3D>(); List <Triangle3D> triangle3Ds = face.Triangulate(1)?.ToSAM(tolerance)?.GetTriangles(); foreach (Triangle3D triangle3D in triangle3Ds) { Polygon3D polygon3D = Spatial.Create.Polygon3D(triangle3D); if (polygon3D == null) { continue; } result.Add(polygon3D); } return(result); }
/// <summary> /// Draws an analysis zone in Dynamo. Use this to identify which zone is which in the CreateFromMass/CreateFromMassAndLevels 'ZoneIds' output list. /// </summary> /// <param name="ZoneId">The ElementId of the zone to draw. Get this from the AnalysisZones > CreateFrom* > ZoneIds output list</param> /// <returns>A list of Dynamo meshes for each zone.</returns> public static List <Autodesk.DesignScript.Geometry.Mesh> DrawAnalysisZone(ElementId ZoneId) { //local varaibles Document RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document; MassZone zone = null; Autodesk.Revit.DB.ElementId myEnergyModelId = null; // get zone data from the document using the id try { zone = (MassZone)RvtDoc.GetElement(new Autodesk.Revit.DB.ElementId(ZoneId.InternalId)); if (zone == null) { throw new Exception(); } } catch (Exception) { throw new Exception("Couldn't find a zone object with Id #: " + ZoneId.ToString()); } //try to get the element id of the MassEnergyAnalyticalModel - we need this to pull faces from try { myEnergyModelId = zone.MassEnergyAnalyticalModelId; // myEnergyModelId = MassEnergyAnalyticalModel.GetMassEnergyAnalyticalModelIdForMassInstance(RvtDoc, MassFamilyInstance.InternalElement.Id); if (myEnergyModelId == null) { throw new Exception(); } } catch (Exception) { //throw new Exception("Couldn't find a MassEnergyAnalyticalModel object belonging to the Mass instance with Id #: " + MassFamilyInstance.InternalElement.Id.ToString()); throw new Exception("Couldn't find a MassEnergyAnalyticalModel object belonging to the Mass instance with Id #: " + zone.MassEnergyAnalyticalModelId.ToString()); } //return a list of all fo the mesh faces for each zone List <Autodesk.DesignScript.Geometry.Mesh> outMeshes = new List <Autodesk.DesignScript.Geometry.Mesh>(); //get references to all of the faces IList <Reference> faceRefs = zone.GetReferencesToEnergyAnalysisFaces(); foreach (var faceRef in faceRefs) { //get the actual face and add the converted version to our list Autodesk.Revit.DB.Face face = (Autodesk.Revit.DB.Face)zone.GetGeometryObjectFromReference(faceRef); outMeshes.Add(Revit.GeometryConversion.RevitToProtoMesh.ToProtoType(face.Triangulate())); } return(outMeshes); }
public static void DrawFace(RenderDescription description, object obj) { Autodesk.Revit.DB.Face face = obj as Autodesk.Revit.DB.Face; if (face == null) { return; } Mesh3D[] meshes = RevitMeshToHelixMesh(face.Triangulate(0.2)); foreach (Mesh3D mesh in meshes) { description.meshes.Add(mesh); } }
public static List <Triangle3f> TriangulateG3(this Autodesk.Revit.DB.Face _face) { var mesh = _face.Triangulate(); var count = mesh.NumTriangles; var list = new List <Triangle3f>(); for (int i = 0; i < count; i++) { var t = mesh.get_Triangle(i); var triangle = new Triangle3f (t.get_Vertex(0).ToVector3f(), t.get_Vertex(1).ToVector3f(), t.get_Vertex(2).ToVector3f()); list.Add(triangle); } return(list); }
/// <summary> /// Draws a mesh in Dynamo representing an analysis surface. Useful when trying to identify a surface to modify. /// </summary> /// <param name="SurfaceId">The ElementId of the surface to draw. Get this from AnalysisZones > CreateFrom* > SurfaceIds output list</param> /// <returns></returns> public static Autodesk.DesignScript.Geometry.Mesh DrawAnalysisSurface(ElementId SurfaceId) { //local varaibles Document RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document; MassSurfaceData surf = null; Autodesk.Revit.DB.ElementId myEnergyModelId = null; //try to get the MassSurfaceData object from the document try { surf = (MassSurfaceData)RvtDoc.GetElement(new Autodesk.Revit.DB.ElementId(SurfaceId.InternalId)); if (surf == null) { throw new Exception(); } } catch (Exception) { throw new Exception("Couldn't find a MassSurfaceData object with Id #: " + SurfaceId.ToString()); } //try to get the element id of the MassEnergyAnalyticalModel - we need this to pull faces from try { myEnergyModelId = surf.ReferenceElementId; if (myEnergyModelId == null) { throw new Exception(); } } catch (Exception) { throw new Exception("Couldn't find a MassEnergyAnalyticalModel object belonging to the Mass instance with Id #: " + surf.ReferenceElementId.ToString()); } //get the smallest face Autodesk.Revit.DB.Face smallFace = GetSmallestFace(RvtDoc, surf, myEnergyModelId); Autodesk.Revit.DB.Mesh prettyMesh = smallFace.Triangulate(); return(Revit.GeometryConversion.RevitToProtoMesh.ToProtoType(prettyMesh)); }