public static Autodesk.DesignScript.Geometry.PolyCurve ToProtoType(this Autodesk.Revit.DB.CurveArray revitCurves, bool performHostUnitConversion = true) { if (revitCurves == null) { throw new ArgumentNullException("revitCurves"); } var protoCurves = revitCurves.Cast <Autodesk.Revit.DB.Curve>().Select(x => x.ToProtoType(false)); var converted = PolyCurve.ByJoinedCurves(protoCurves.ToArray()); foreach (var curve in protoCurves) { curve.Dispose(); } if (converted == null) { throw new Exception("An unexpected failure occurred when attempting to convert the curve"); } if (performHostUnitConversion) { UnitConverter.ConvertToDynamoUnits(ref converted); } return(converted); }
public static Autodesk.DesignScript.Geometry.Curve ToProtoType(this Autodesk.Revit.DB.Curve revitCurve, bool performHostUnitConversion = true, Reference referenceOverride = null) { if (revitCurve == null) { throw new ArgumentNullException("revitCurve"); } dynamic dyCrv = revitCurve; Autodesk.DesignScript.Geometry.Curve converted = RevitToProtoCurve.Convert(dyCrv); if (converted == null) { throw new Exception("An unexpected failure occurred when attempting to convert the curve"); } if (performHostUnitConversion) { UnitConverter.ConvertToDynamoUnits(ref converted); } // If possible, add a geometry reference for downstream Element creation var revitRef = referenceOverride ?? revitCurve.Reference; if (revitRef != null) { converted.Tags.AddTag(ElementCurveReference.DefaultTag, revitRef); } return(converted); }
public static Autodesk.DesignScript.Geometry.PolyCurve ToProtoType(this Autodesk.Revit.DB.PolyLine geom, bool performHostUnitConversion = true) { var converted = PolyCurve.ByPoints(geom.GetCoordinates().Select(x => Autodesk.DesignScript.Geometry.Point.ByCoordinates(x.X, x.Y, x.Z)).ToArray()); if (performHostUnitConversion) { UnitConverter.ConvertToDynamoUnits(ref converted); } return(converted); }
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)); } var converted = Solid.ByJoinedSurfaces(srfs); srfs.ForEach(x => x.Dispose()); srfs.Clear(); if (performHostUnitConversion) { UnitConverter.ConvertToDynamoUnits(ref converted); } return(converted); }
public static IEnumerable <Surface> ToProtoType(this Autodesk.Revit.DB.Face revitFace, bool performHostUnitConversion = true, Reference referenceOverride = null) { if (revitFace == null) { throw new ArgumentNullException("revitFace"); } var revitEdgeLoops = EdgeLoopPartition.GetAllEdgeLoopsFromRevitFace(revitFace); var partitionedRevitEdgeLoops = EdgeLoopPartition.ByEdgeLoopsAndFace(revitFace, revitEdgeLoops); var listSurface = new List <Surface>(); foreach (var edgeloopPartition in partitionedRevitEdgeLoops) { // convert the trimming curves var edgeLoops = EdgeLoopsAsPolyCurves(revitFace, edgeloopPartition); // convert the underrlying surface var dyFace = (dynamic)revitFace; Surface untrimmedSrf = SurfaceExtractor.ExtractSurface(dyFace, edgeLoops); if (untrimmedSrf == null) { edgeLoops.ForEach(x => x.Dispose()); edgeLoops.Clear(); throw new Exception("Failed to extract surface"); } // trim the surface Surface converted; try { converted = untrimmedSrf.TrimWithEdgeLoops(edgeLoops); } catch (Exception e) { edgeLoops.ForEach(x => x.Dispose()); edgeLoops.Clear(); untrimmedSrf.Dispose(); throw e; } edgeLoops.ForEach(x => x.Dispose()); edgeLoops.Clear(); untrimmedSrf.Dispose(); // perform unit conversion if necessary if (performHostUnitConversion) { UnitConverter.ConvertToDynamoUnits(ref converted); } // if possible, apply revit reference var revitRef = referenceOverride ?? revitFace.Reference; if (revitRef != null) { converted = ElementFaceReference.AddTag(converted, revitRef); } listSurface.Add(converted); } return(listSurface); }