Example #1
0
 public static List <PolyCurve> GetEdgeLoopsFromRevitFaceAsPolyCurves(Autodesk.Revit.DB.Face face)
 {
     return(face.EdgeLoops.Cast <EdgeArray>()
            .Select(x => x.Cast <Autodesk.Revit.DB.Edge>())
            .Select(x => x.Select(t => t.AsCurveFollowingFace(face).ToProtoType(false)))
            .Select(PolyCurve.ByJoinedCurves)
            .ToList());
 }
Example #2
0
        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);
        }
Example #3
0
 public static IEnumerable <IEnumerable <Autodesk.Revit.DB.Edge> > GetEdgeLoopsFromRevitFace(Autodesk.Revit.DB.Face face)
 {
     return(face.EdgeLoops.Cast <EdgeArray>()
            .Select(x => x.Cast <Autodesk.Revit.DB.Edge>()));
 }
Example #4
0
 public static IEnumerable <Surface> GetTrimmedSurfacesFromFace(Autodesk.Revit.DB.Face geom)
 {
     return(geom.ToProtoType(false));
 }
Example #5
0
        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);
        }