public static IEnumerable <Surface> ToProtoType(this Autodesk.Revit.DB.Face revitFace, bool performHostUnitConversion = true) { 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) { throw new Exception("Failed to extract surface"); } // trim the surface Surface converted = untrimmedSrf.TrimWithEdgeLoops(edgeLoops); // perform unit conversion if necessary converted = performHostUnitConversion ? converted.InDynamoUnits() : converted; // if possible, apply revit reference var revitRef = revitFace.Reference; if (revitRef != null) { converted = ElementFaceReference.AddTag(converted, revitRef); } listSurface.Add(converted); } return(listSurface); }
public static Surface ToProtoType(this Autodesk.Revit.DB.Face revitFace) { if (revitFace == null) { return(null); } var dyFace = (dynamic)revitFace; List <PolyCurve> edgeLoops = EdgeLoopsAsPolyCurves(dyFace); Surface untrimmedSrf = SurfaceExtractor.ExtractSurface(dyFace, edgeLoops); var converted = untrimmedSrf != null?untrimmedSrf.TrimWithEdgeLoops(edgeLoops.ToArray()) : null; if (converted == null) { return(null); } var revitRef = revitFace.Reference; return(revitRef != null?ElementFaceReference.AddTag(converted, revitRef) : converted); }
private static Autodesk.DesignScript.Geometry.Surface Tag(Autodesk.DesignScript.Geometry.Surface srf, Autodesk.Revit.DB.Reference reference) { return(reference != null?ElementFaceReference.AddTag(srf, reference) : srf); }
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 revitCurveLoops = CurveLoopPartition.GetAllCurveloopsFromRevitFace(revitFace); var partitionedRevitCurveLoops = CurveLoopPartition.ByCurveLoops(revitCurveLoops); var listSurface = new List <Surface>(); foreach (var curveloopPartition in partitionedRevitCurveLoops) { // convert the trimming curves var curveLoops = CurveLoopsAsPolyCurves(revitFace, curveloopPartition.GetAllCurves()); // convert the underrlying surface var dyFace = (dynamic)revitFace; Surface untrimmedSrf = SurfaceExtractor.ExtractSurface(dyFace, curveLoops); if (untrimmedSrf == null) { curveLoops.ForEach(x => x.Dispose()); curveLoops.Clear(); throw new Exception("Failed to extract surface"); } // trim the surface Surface converted; try { converted = untrimmedSrf.TrimWithEdgeLoops(curveLoops); } catch (Exception e) { curveLoops.ForEach(x => x.Dispose()); curveLoops.Clear(); untrimmedSrf.Dispose(); throw e; } curveLoops.ForEach(x => x.Dispose()); curveLoops.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); }