/// <summary> /// Extract a 3D solid from a Revit GeometryObject /// </summary> /// <param name="geoObject"></param> /// <param name="_outSolid"></param> /// <returns></returns> public static bool TryeGetGeometryDataFromGeometryObject(GeometryObject geoObject, out Solid _outSolid, out DynamoSolid _outDynSolid) { DynamoSolid outdynSolid = null; Solid outSolid = null; bool success; // Check if its is a Geometry Instance if (geoObject is GeometryInstance) { GeometryInstance geoInstance = geoObject as GeometryInstance; foreach (Solid solid in geoInstance.GetInstanceGeometry()) { // Skip to next element in iteration if any of the following conditions are met if (null == solid || 0 == solid.Faces.Size || 0 == solid.Edges.Size) { continue; } DynamoSolid dynSolidGeo = ToDynamoSolid(solid); // Sometimes a geometry element can be a null solid if (dynSolidGeo != null) { outdynSolid = dynSolidGeo; outSolid = solid; } } } // Check if it is Solid else if (geoObject is Solid) { Solid solid = geoObject as Solid; DynamoSolid dynSolidGeo = ToDynamoSolid(solid); // Sometimes a geometry element can be a null solid if (dynSolidGeo != null) { outdynSolid = dynSolidGeo; outSolid = solid; } } if (outdynSolid == null && outSolid == null) { success = false; } else { success = true; } _outDynSolid = outdynSolid; _outSolid = outSolid; return(success); }
/// <summary> /// /// </summary> /// <param name="geoElement"></param> /// <param name="outPutSolids"></param> private static void ProcessStairs(GeometryElement geoElement, List <DynamoSolid> outPutSolids) { for (int j = 0; j < geoElement.Count(); j++) { GeometryInstance geoIns = geoElement.ElementAt(j) as GeometryInstance; //GetInstanceGeometry returns the geometry represented in the coordinate system of the project where the instance is placed. // https://thebuildingcoder.typepad.com/blog/2010/01/geometry-options.html GeometryElement instanceGeo = geoIns.GetInstanceGeometry(); foreach (var item in instanceGeo) { if (item is Solid) { Solid solid = item as Solid; // Skip item if does not contain solid geo if (solid == null) { continue; } DynamoSolid solidGeo = GeometryExtraction.ToDynamoSolid(solid); // Skip item if does not contain solid geo if (solidGeo == null) { continue; } outPutSolids.Add(solidGeo); } } } }
/// <summary> /// Create a Void Family Type from a solid geometry. /// This method exports the solid to SAT and imports it into /// a new family document. /// </summary> /// <param name="solidGeometry"></param> /// <param name="name">Name to apply to the Family Type</param> /// <param name="category">Category to apply</param> /// <param name="templatePath">Template file to use for creation</param> /// <returns>Void Family Type</returns> public static FamilyType VoidByGeometry(Autodesk.DesignScript.Geometry.Solid solidGeometry, string name, Category category, string templatePath) { var symbol = solidGeometry.ToRevitFamilyType(name, category, templatePath, null, true, string.Empty); return(new FamilyType(symbol) { IsRevitOwned = true }); }
/// <summary> /// Create new Family Type from a solid geometry. /// This method exports the geometry to SAT and imports it into /// a new family document. /// </summary> /// <param name="solidGeometry"></param> /// <param name="name">Name fo the Family Type</param> /// <param name="category">Family Type Category</param> /// <param name="templatePath">Family Template to use for creation</param> /// <param name="material">Material to apply to the solids</param> /// <param name="subcategory">Subcategory for the Family Type (optional)</param> /// <returns>Family Type</returns> public static FamilyType ByGeometry(Autodesk.DesignScript.Geometry.Solid solidGeometry, string name, Category category, string templatePath, Material material, string subcategory = "") { var symbol = solidGeometry.ToRevitFamilyType(name, category, templatePath, material, false, subcategory); return(new FamilyType(symbol) { IsRevitOwned = true }); }
/// <summary> /// this method attempts to construct a BRep from a closed solid. /// </summary> /// <param name="sol"></param> /// <param name="performHostUnitConversion"></param> /// <param name="materialId"></param> /// <returns></returns> public static GeometryObject ToRevitType(Solid sol, bool performHostUnitConversion = true, ElementId materialId = null) { var geometry = ToRevitType(sol, performHostUnitConversion, BRepType.Solid, materialId); if (geometry == null) { // An unexpected failure occurred when attempting to convert the solid into a Revit BRep. throw new Exception(Properties.Resources.DynamoSolidToRevitBRepFailure); } return(geometry); }
public static IList <GeometryObject> ToRevitType( this Autodesk.DesignScript.Geometry.Solid solid, bool performHostUnitConversion = true) { var rp = new RenderPackage(); if (performHostUnitConversion) { var newSolid = solid.InHostUnits(); newSolid.Tessellate(rp); newSolid.Dispose(); } else { solid.Tessellate(rp); } var tsb = new TessellatedShapeBuilder(); tsb.OpenConnectedFaceSet(false); var v = rp.TriangleVertices; for (int i = 0; i < v.Count; i += 9) { var a = new XYZ(v[i], v[i + 1], v[i + 2]); var b = new XYZ(v[i + 3], v[i + 4], v[i + 5]); var c = new XYZ(v[i + 6], v[i + 7], v[i + 8]); var face = new TessellatedFace(new List <XYZ>() { a, b, c }, MaterialsManager.Instance.DynamoMaterialId); tsb.AddFace(face); } tsb.CloseConnectedFaceSet(); var result = tsb.Build(TessellatedShapeBuilderTarget.Mesh, TessellatedShapeBuilderFallback.Salvage, ElementId.InvalidElementId); return(result.GetGeometricalObjects()); }
public static Autodesk.DesignScript.Geometry.Solid ToProtoType(this Autodesk.Revit.DB.Solid solid, bool performHostUnitConversion = true) { var faces = solid.Faces; var srfs = new List <Surface>(); foreach (Face face in faces) { srfs.AddRange(face.ToProtoType(false)); } Solid converted = null; try { converted = Solid.ByJoinedSurfaces(srfs); } catch (Exception) { return(null); } finally { srfs.ForEach(x => x.Dispose()); srfs.Clear(); } if (converted == null) { return(null); } if (performHostUnitConversion) { UnitConverter.ConvertToDynamoUnits(ref converted); } return(converted); }
public static Brep ToRhinoType(Autodesk.DesignScript.Geometry.Solid solid, double RhinoDocTol) { int n = solid.Faces.Length; double tol = 0.0001; Brep[] faces = new Brep[n]; for (int i = 0; i < n; i++) { Point3d [] verts = ToRhinoType(solid.Vertices.Select(a => a.PointGeometry).ToArray()).ToArray(); if (verts.Length < 3) { throw new ParasiteArgumentException("A Brep Face cant be constructed from less than 2 vertices!"); } else if (verts.Length == 3) { Point3d a = verts[0]; Point3d b = verts[1]; Point3d c = verts[2]; faces[i] = Brep.CreateFromCornerPoints(a, b, c, RhinoDocTol); } else if (verts.Length == 4) { Point3d a = verts[0]; Point3d b = verts[1]; Point3d c = verts[2]; Point3d d = verts[3]; faces[i] = Brep.CreateFromCornerPoints(a, b, c, d, RhinoDocTol); } /// Build curve from vertices to then build a Brep face else { IEnumerable <Curve> edgesAsCurves = ToRhinoType(solid.Faces[i].Edges); Brep[] b = Brep.CreatePlanarBreps(edgesAsCurves, RhinoDocTol); faces[i] = b[0]; } } Brep output = null; try { Brep[] joinedBreps = Brep.JoinBreps(faces, tol); output = joinedBreps[0]; } catch { if (output == null) { // Check if folder exists, if not create it. if (!Directory.Exists(FolderInfo.dirPath)) { Directory.CreateDirectory(FolderInfo.dirPath); } string pathToFolder = Path.Combine(FolderInfo.dirPath, "RebelBreps"); FileStream fs = new FileStream(pathToFolder, FileMode.Create); // Construct a BinaryFormatter and use it to serialize the data to the stream. BinaryFormatter formatter = new BinaryFormatter(); try { formatter.Serialize(fs, faces); } catch (SerializationException e) { throw new SerializationException("Failed to serialize: " + e.Message); } finally { fs.Close(); } throw new ParasiteConversionExceptions(output.GetType(), solid.GetType()); } } return(output); }