public static Vector ToVector(this XYZ xyz, bool convertUnits = false) { var v = Autodesk.DesignScript.Geometry.Vector.ByCoordinates(xyz.X, xyz.Y, xyz.Z); return(convertUnits ? v.Scale(UnitConverter.HostToDynamoFactor(SpecTypeId.Length)) : v); }
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); }