예제 #1
0
        public Surface FaceToSpeckle(DB.Face face, out bool parametricOrientation, double relativeTolerance = 0.0, string units = null)
        {
            var u = units ?? ModelUnits;

            using (var surface = face.GetSurface())
                parametricOrientation = surface.OrientationMatchesParametricOrientation;

            switch (face)
            {
            case null:
                return(null);

            case PlanarFace planar:
                return(FaceToSpeckle(planar, relativeTolerance, u));

            case ConicalFace conical:
                return(FaceToSpeckle(conical, relativeTolerance, u));

            case CylindricalFace cylindrical:
                return(FaceToSpeckle(cylindrical, relativeTolerance, u));

            case RevolvedFace revolved:
                return(FaceToSpeckle(revolved, relativeTolerance, u));

            case RuledFace ruled:
                return(FaceToSpeckle(ruled, relativeTolerance, u));

            case HermiteFace hermite:
                return(FaceToSpeckle(hermite, face.GetBoundingBox(), u));

            default:
                throw new NotImplementedException();
            }
        }
예제 #2
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            object arg0 = ((Value.Container)args[0]).Item;

            Autodesk.Revit.DB.Face f = null;
            if (arg0 is Reference)
            {
                Reference faceRef = arg0 as Reference;
                f = dynRevitSettings.Doc.Document.GetElement(faceRef.ElementId).GetGeometryObjectFromReference(faceRef) as Autodesk.Revit.DB.Face;
            }

            double d    = ((Value.Number)args[1]).Item;      //dampening
            double s    = ((Value.Number)args[2]).Item;      //spring constant
            double r    = ((Value.Number)args[3]).Item;      //rest length
            double m    = ((Value.Number)args[4]).Item;      //nodal mass
            int    numX = (int)((Value.Number)args[5]).Item; //number of particles in X
            int    numY = (int)((Value.Number)args[6]).Item; //number of particles in Y
            double g    = ((Value.Number)args[7]).Item;      //gravity z component

            particleSystem.setIsFaceConstrained(true);
            particleSystem.setConstraintFace(f);

            particleSystem.Clear();

            setupParticleSystem(f, numX, numY, d, r, s, m);
            particleSystem.setGravity(g);

            return(Value.NewContainer(particleSystem));
        }
예제 #3
0
        public static List <Polygon3D> ToSAM_Polygon3Ds(this Autodesk.Revit.DB.Face face, double tolerance = Core.Tolerance.Distance)
        {
            if (face == null)
            {
                return(null);
            }

            if (face is PlanarFace)
            {
                return(ToSAM_Polygon3Ds((PlanarFace)face, tolerance));
            }

            List <Polygon3D> result = new List <Polygon3D>();

            List <Triangle3D> triangle3Ds = face.Triangulate(1)?.ToSAM(tolerance)?.GetTriangles();

            foreach (Triangle3D triangle3D in triangle3Ds)
            {
                Polygon3D polygon3D = Spatial.Create.Polygon3D(triangle3D);
                if (polygon3D == null)
                {
                    continue;
                }

                result.Add(polygon3D);
            }

            return(result);
        }
예제 #4
0
        public static Surface GetUntrimmedSurfaceFromRevitFace(Face geom,
                                                               IEnumerable <PolyCurve> edgeLoops)
        {
            var dyFace = (dynamic)geom;

            return((Surface)SurfaceExtractor.ExtractSurface(dyFace, edgeLoops));
        }
예제 #5
0
        static Surface ToRhinoSurface(this DB.Face face)
        {
            Surface surface = default;

            using (var faceSurface = face.GetSurface())
            {
                var bboxUV = face.GetBoundingBox();

                switch (faceSurface)
                {
                case DB.Plane planeSurface:                     surface = planeSurface.ToRhino(bboxUV);       break;

                case DB.ConicalSurface conicalSurface:          surface = conicalSurface.ToRhino(bboxUV);     break;

                case DB.CylindricalSurface cylindricalSurface:  surface = cylindricalSurface.ToRhino(bboxUV); break;

                case DB.RevolvedSurface revolvedSurface:        surface = revolvedSurface.ToRhino(bboxUV);    break;

                case DB.RuledSurface ruledSurface:              surface = ruledSurface.ToRhino(bboxUV);       break;

                case DB.HermiteSurface hermiteSurface:
                    try
                    {
                        using (var nurbsData = DB.ExportUtils.GetNurbsSurfaceDataForFace(face))
                            surface = nurbsData.ToRhino(bboxUV);
                    }
                    catch (Autodesk.Revit.Exceptions.ArgumentException) { }
                    break;

                default: throw new NotImplementedException();
                }
            }

            return(surface);
        }
예제 #6
0
        internal static Brep ToBrep(DB.Face face)
        {
            var surface = Raw.RawDecoder.ToRhinoSurface(face, out var _, 1.0);

            if (surface is null)
            {
                return(null);
            }

            var brep = Brep.CreateFromSurface(surface);

            if (brep is null)
            {
                return(null);
            }

            if (!face.MatchesSurfaceOrientation())
            {
                brep.Flip();
            }

            var loops = ToCurveMany(face.GetEdgesAsCurveLoops()).ToArray();

            try { return(TrimFaces(brep, loops)); }
            finally { brep.Dispose(); }
        }
예제 #7
0
        void setupParticleSystem(Autodesk.Revit.DB.Face f, int uDiv, int vDiv, double springDampening, double springRestLength, double springConstant, double mass)
        {
            BoundingBoxUV bbox  = f.GetBoundingBox();
            double        uStep = (bbox.Max.U - bbox.Min.U) / uDiv;
            double        vStep = (bbox.Max.V - bbox.Min.V) / vDiv;

            for (int j = 0; j <= uDiv; j++) // Y axis is outer loop
            {
                double u = bbox.Min.U + uStep * j;

                for (int i = 0; i <= vDiv; i++) // X axis is inner loop
                {
                    double v = bbox.Min.V + vStep * i;

                    Particle a = particleSystem.makeParticle(mass, f.Evaluate(new UV(u, v)), false);
                    if (i > 0)
                    {
                        particleSystem.makeSpring(particleSystem.getParticle((i - 1) + (j * (vDiv + 1))), a, springRestLength, springConstant, springDampening);
                    }

                    if (j > 0)
                    {
                        Particle b = particleSystem.getParticle(i + ((j - 1) * (vDiv + 1)));
                        particleSystem.makeSpring(a, b, springRestLength, springConstant, springDampening);
                    }

                    if (i == 0 || i == vDiv || j == 0 || j == uDiv)
                    {
                        a.makeFixed();
                    }
                }
            }
        }
예제 #8
0
        public static Brep ToRhino(this DB.Face face, bool untrimmed = false)
        {
            var surface = face.ToRhinoSurface();

            if (surface is null)
            {
                return(null);
            }

            var brep = Brep.CreateFromSurface(surface);

            if (brep is null)
            {
                return(null);
            }

#if REVIT_2018
            if (!face.OrientationMatchesSurfaceOrientation)
            {
                brep.Flip();
            }
#endif
            if (untrimmed)
            {
                return(brep);
            }

            var loops = face.GetEdgesAsCurveLoops().ToRhino().ToArray();

            try { return(brep.TrimFaces(loops)); }
            finally { brep.Dispose(); }
        }
예제 #9
0
        public static List <Spatial.Face3D> BottomProfiles(this HostObject hostObject)
        {
            List <Spatial.Face3D> result = new List <Spatial.Face3D>();

            foreach (Reference reference in HostObjectUtils.GetBottomFaces(hostObject))
            {
                GeometryObject geometryObject = hostObject.GetGeometryObjectFromReference(reference);
                if (geometryObject == null)
                {
                    continue;
                }

                Autodesk.Revit.DB.Face face = geometryObject as Autodesk.Revit.DB.Face;
                if (face == null)
                {
                    continue;
                }

                List <Spatial.Face3D> face3Ds = face.ToSAM();
                if (face3Ds == null || face3Ds.Count == 0)
                {
                    continue;
                }

                result.AddRange(face3Ds);
            }

            return(result);
        }
예제 #10
0
 private static List <PolyCurve> EdgeLoopsAsPolyCurves(Face face,
                                                       IEnumerable <IEnumerable <Edge> > edgeLoops)
 {
     return(edgeLoops
            .Select(x => x.Select(t => t.AsCurveFollowingFace(face).ToProtoType(false)))
            .Select(PolyCurve.ByJoinedCurves)
            .ToList());
 }
예제 #11
0
 private static List<PolyCurve> EdgeLoopsAsPolyCurves(Face face, 
     IEnumerable<IEnumerable<Edge>> edgeLoops)
 {
     return edgeLoops
         .Select(x => x.Select(t => t.AsCurveFollowingFace(face).ToProtoType(false)))
         .Select(PolyCurve.ByJoinedCurves)
         .ToList();
 }
예제 #12
0
 internal static List <PolyCurve> EdgeLoopsAsPolyCurves(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()).ToArray())
            .Select(PolyCurve.ByJoinedCurves)
            .ToList());
 }
예제 #13
0
 internal ElementFaceReference(Autodesk.Revit.DB.Face face)
 {
     if (face.Reference == null)
     {
         throw new Exception(Properties.Resources.FaceReferenceFailure);
     }
     this.InternalReference = face.Reference;
 }
        /// <summary>
        /// Draws a point around the center of an analysis surface.  Useful for sorting/grouping surfaces upstream of a SetSurfaceParameters node.
        /// </summary>
        /// <param name="SurfaceId">The ElementId of the surface to create a point from.  Get this from the AnalysisZones > CreateFrom* > SurfaceIds output list</param>
        /// <returns></returns>
        public static Autodesk.DesignScript.Geometry.Point AnalysisSurfacePoint(ElementId SurfaceId)
        {
            //local varaibles
            Document        RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document;
            MassSurfaceData surf   = null;

            Autodesk.Revit.DB.ElementId myEnergyModelId = null;

            //try to get the MassSurfaceData object from the document
            try
            {
                surf = (MassSurfaceData)RvtDoc.GetElement(new Autodesk.Revit.DB.ElementId(SurfaceId.InternalId));
                if (surf == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw new Exception("Couldn't find a MassSurfaceData object with Id #: " + SurfaceId.ToString());
            }

            //try to get the element id of the MassEnergyAnalyticalModel - we need this to pull faces from
            try
            {
                myEnergyModelId = surf.ReferenceElementId;
                if (myEnergyModelId == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw new Exception("Couldn't find a MassEnergyAnalyticalModel object belonging to the Mass instance with Id #: " + surf.ReferenceElementId.ToString());
            }

            //try to get the MassSurfaceData object from the document
            try
            {
                surf = (MassSurfaceData)RvtDoc.GetElement(new Autodesk.Revit.DB.ElementId(SurfaceId.InternalId));
                if (surf == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw new Exception("Couldn't find a MassSurfaceData object with Id #: " + SurfaceId.ToString());
            }

            //get the smallest face
            Autodesk.Revit.DB.Face smallFace = GetSmallestFace(RvtDoc, surf, myEnergyModelId);

            //get the average point of all points on the face
            Autodesk.DesignScript.Geometry.Point outPoint = getAveragePointFromFace(smallFace);
            return(outPoint);
        }
예제 #15
0
        public static List <Polygon3D> ToSAM_Polygon3Ds(this Autodesk.Revit.DB.Face face)
        {
            if (face == null)
            {
                return(null);
            }

            return(ToSAM_Polygon3Ds(face.GetEdgesAsCurveLoops()));
        }
예제 #16
0
 internal ElementFaceReference(Autodesk.Revit.DB.Face face)
 {
     if (face.Reference == null)
     {
         throw new Exception("A Face Reference can only be obtained "
                             + "from an Element.");
     }
     this.InternalReference = face.Reference;
 }
예제 #17
0
        public Geometry.Surface FaceToSpeckle(DB.Face face, DB.BoundingBoxUV uvBox, string units = null)
        {
#if (REVIT2021 || REVIT2022)
            var surf = DB.ExportUtils.GetNurbsSurfaceDataForSurface(face.GetSurface());
#else
            var surf = DB.ExportUtils.GetNurbsSurfaceDataForFace(face);
#endif
            var spcklSurface = NurbsSurfaceToSpeckle(surf, face.GetBoundingBox(), units ?? ModelUnits);
            return(spcklSurface);
        }
        private static Autodesk.DesignScript.Geometry.Point getAveragePointFromFace(Autodesk.Revit.DB.Face f)
        {
            //the point to return
            Autodesk.DesignScript.Geometry.Point p = null;

            //if face is a ruled face
            RuledFace rf = f as RuledFace;

            if (rf != null)
            {
                //units seem to be messed up...  convert to a designscript mesh first, then pull from that
                Autodesk.DesignScript.Geometry.Mesh m = Revit.GeometryConversion.RevitToProtoMesh.ToProtoType(rf.Triangulate());
                var points = m.VertexPositions;


                int    numVertices = points.Count();
                double x = 0, y = 0, z = 0;
                foreach (var v in points)
                {
                    x = x + v.X;
                    y = y + v.Y;
                    z = z + v.Z;
                }
                x = x / numVertices;
                y = y / numVertices;
                z = z / numVertices;
                p = Autodesk.DesignScript.Geometry.Point.ByCoordinates(x, y, z);
            }
            else // if it isn't a ruled face, treat it as planar
            {
                PlanarFace pf = f as PlanarFace;
                if (pf != null)
                {
                    //units seem to be messed up...  convert to a designscript mesh first, then pull from that
                    Autodesk.DesignScript.Geometry.Mesh m = Revit.GeometryConversion.RevitToProtoMesh.ToProtoType(pf.Triangulate());
                    var points = m.VertexPositions;


                    int    numVertices = points.Count();
                    double x = 0, y = 0, z = 0;
                    foreach (var v in points)
                    {
                        x = x + v.X;
                        y = y + v.Y;
                        z = z + v.Z;
                    }
                    x = x / numVertices;
                    y = y / numVertices;
                    z = z / numVertices;
                    p = Autodesk.DesignScript.Geometry.Point.ByCoordinates(x, y, z);
                }
            }
            return(p);
        }
예제 #19
0
        public Geometry.Surface FaceToSpeckle(DB.Face face, DB.BoundingBoxUV uvBox)
        {
#if REVIT2021
            var surf = DB.ExportUtils.GetNurbsSurfaceDataForSurface(face.GetSurface());
#else
            var surf = DB.ExportUtils.GetNurbsSurfaceDataForFace(face);
#endif

            var spcklSurface = NurbsSurfaceToSpeckle(surf, face.GetBoundingBox());
            return(spcklSurface);
        }
        /// <summary>
        /// Draws an analysis zone in Dynamo.  Use this to identify which zone is which in the CreateFromMass/CreateFromMassAndLevels 'ZoneIds' output list.
        /// </summary>
        /// <param name="ZoneId">The ElementId of the zone to draw.  Get this from the AnalysisZones > CreateFrom* > ZoneIds output list</param>
        /// <returns>A list of Dynamo meshes for each zone.</returns>
        public static List <Autodesk.DesignScript.Geometry.Mesh> DrawAnalysisZone(ElementId ZoneId)
        {
            //local varaibles
            Document RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document;
            MassZone zone   = null;

            Autodesk.Revit.DB.ElementId myEnergyModelId = null;

            // get zone data from the document using the id
            try
            {
                zone = (MassZone)RvtDoc.GetElement(new Autodesk.Revit.DB.ElementId(ZoneId.InternalId));

                if (zone == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw new Exception("Couldn't find a zone object with Id #: " + ZoneId.ToString());
            }


            //try to get the element id of the MassEnergyAnalyticalModel - we need this to pull faces from
            try
            {
                myEnergyModelId = zone.MassEnergyAnalyticalModelId;
                // myEnergyModelId = MassEnergyAnalyticalModel.GetMassEnergyAnalyticalModelIdForMassInstance(RvtDoc, MassFamilyInstance.InternalElement.Id);
                if (myEnergyModelId == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                //throw new Exception("Couldn't find a MassEnergyAnalyticalModel object belonging to the Mass instance with Id #: " + MassFamilyInstance.InternalElement.Id.ToString());
                throw new Exception("Couldn't find a MassEnergyAnalyticalModel object belonging to the Mass instance with Id #: " + zone.MassEnergyAnalyticalModelId.ToString());
            }

            //return a list of all fo the mesh faces for each zone
            List <Autodesk.DesignScript.Geometry.Mesh> outMeshes = new List <Autodesk.DesignScript.Geometry.Mesh>();
            //get references to all of the faces
            IList <Reference> faceRefs = zone.GetReferencesToEnergyAnalysisFaces();

            foreach (var faceRef in faceRefs)
            {
                //get the actual face and add the converted version to our list
                Autodesk.Revit.DB.Face face = (Autodesk.Revit.DB.Face)zone.GetGeometryObjectFromReference(faceRef);
                outMeshes.Add(Revit.GeometryConversion.RevitToProtoMesh.ToProtoType(face.Triangulate()));
            }
            return(outMeshes);
        }
예제 #21
0
        public static Surface ToProtoType(this Autodesk.Revit.DB.Face face)
        {
            if (face == null)
            {
                return(null);
            }

            dynamic          dyFace       = face;
            List <PolyCurve> edgeLoops    = EdgeLoopsAsPolyCurves(dyFace);
            Surface          untrimmedSrf = SurfaceExtractor.ExtractSurface(dyFace, edgeLoops);

            return(untrimmedSrf != null?untrimmedSrf.TrimWithEdgeLoops(edgeLoops.ToArray()) : null);
        }
예제 #22
0
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            Solid thisSolid  = (Solid)((FScheme.Value.Container)args[0]).Item;
            Line  selectLine = (Line)((FScheme.Value.Container)args[1]).Item;

            FaceArray faceArr  = thisSolid.Faces;
            var       thisEnum = faceArr.GetEnumerator();

            SortedList <double, Autodesk.Revit.DB.Face> intersectingFaces = new SortedList <double, Autodesk.Revit.DB.Face>();

            for (; thisEnum.MoveNext();)
            {
                Autodesk.Revit.DB.Face  thisFace    = (Autodesk.Revit.DB.Face)thisEnum.Current;
                IntersectionResultArray resultArray = null;

                SetComparisonResult resultIntersect = thisFace.Intersect(selectLine, out resultArray);
                if (resultIntersect != SetComparisonResult.Overlap)
                {
                    continue;
                }
                bool   first   = true;
                double linePar = -1.0;
                foreach (IntersectionResult ir in resultArray)
                {
                    double irPar = ir.Parameter;
                    if (first == true)
                    {
                        linePar = irPar;
                        first   = false;
                    }
                    else if (irPar < linePar)
                    {
                        linePar = irPar;
                    }
                }
                intersectingFaces.Add(linePar, thisFace);
            }

            var result = FSharpList <FScheme.Value> .Empty;

            var intersectingFacesEnum = intersectingFaces.Reverse().GetEnumerator();

            for (; intersectingFacesEnum.MoveNext();)
            {
                Autodesk.Revit.DB.Face faceObj = intersectingFacesEnum.Current.Value;
                result = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(faceObj), result);
            }

            return(FScheme.Value.NewList(result));
        }
예제 #23
0
        public static void DrawFace(RenderDescription description, object obj)
        {
            Autodesk.Revit.DB.Face face = obj as Autodesk.Revit.DB.Face;

            if (face == null)
            {
                return;
            }

            Mesh3D[] meshes = RevitMeshToHelixMesh(face.Triangulate(0.2));

            foreach (Mesh3D mesh in meshes)
            {
                description.meshes.Add(mesh);
            }
        }
        public static Brep ToRhino(DB.Face face)
        {
            if (face is null)
            {
                return(null);
            }

            var brep = new Brep();

            // Set surface
            var si = AddSurface(brep, face, out var shells);

            if (si < 0)
            {
                return(null);
            }

            // Set edges & trims
            TrimSurface(brep, si, !face.MatchesSurfaceOrientation(), shells);

            // Set vertices
            brep.SetVertices();

            // Set flags
            brep.SetTolerancesBoxesAndFlags
            (
                true,
                true,
                true,
                true,
                true,
                true,
                true,
                true
            );

            if (!brep.IsValid)
            {
#if DEBUG
                brep.IsValidWithLog(out var log);
                Debug.WriteLine($"{MethodInfo.GetCurrentMethod().DeclaringType.FullName}.{MethodInfo.GetCurrentMethod().Name}()\n{log}");
#endif
                brep.Repair(Revit.VertexTolerance);
            }

            return(brep);
        }
예제 #25
0
        public static Brep ToRhino(DB.Face face)
        {
            if (face is null)
            {
                return(null);
            }

            var brep = new Brep();

            // Set surface
            var si = AddSurface(brep, face, out var shells);

            if (si < 0)
            {
                return(null);
            }

            // Set edges & trims
            TrimSurface(brep, si, !face.MatchesSurfaceOrientation(), shells);

            // Set vertices
            brep.SetVertices();

            // Set flags
            brep.SetTolerancesBoxesAndFlags
            (
                true,
                true,
                true,
                true,
                true,
                true,
                true,
                true
            );

            if (!brep.IsValid)
            {
#if DEBUG
                brep.IsValidWithLog(out var log);
#endif
                brep.Repair(Revit.VertexTolerance);
            }

            return(brep);
        }
예제 #26
0
        public static List <Triangle3f> TriangulateG3(this Autodesk.Revit.DB.Face _face)
        {
            var mesh  = _face.Triangulate();
            var count = mesh.NumTriangles;
            var list  = new List <Triangle3f>();

            for (int i = 0; i < count; i++)
            {
                var t        = mesh.get_Triangle(i);
                var triangle = new Triangle3f
                                   (t.get_Vertex(0).ToVector3f(),
                                   t.get_Vertex(1).ToVector3f(),
                                   t.get_Vertex(2).ToVector3f());
                list.Add(triangle);
            }
            return(list);
        }
예제 #27
0
        private static List <PolyCurve> CurveLoopsAsPolyCurves(Face face,
                                                               IEnumerable <IEnumerable <Autodesk.Revit.DB.Curve> > curveLoops)
        {
            List <PolyCurve> result = new List <PolyCurve>();

            foreach (var curveLoop in curveLoops)
            {
                List <Autodesk.DesignScript.Geometry.Curve> curves =
                    new List <Autodesk.DesignScript.Geometry.Curve>();
                foreach (var curve in curveLoop)
                {
                    curves.Add(curve.ToProtoType(false));
                }
                result.Add(PolyCurve.ByJoinedCurves(curves));
                curves.ForEach(x => x.Dispose());
                curves.Clear();
            }
            return(result);
        }
        /// <summary>
        /// Draws a mesh in Dynamo representing an analysis surface.  Useful when trying to identify a surface to modify.
        /// </summary>
        /// <param name="SurfaceId">The ElementId of the surface to draw.  Get this from AnalysisZones > CreateFrom* > SurfaceIds output list</param>
        /// <returns></returns>
        public static Autodesk.DesignScript.Geometry.Mesh DrawAnalysisSurface(ElementId SurfaceId)
        {
            //local varaibles
            Document        RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document;
            MassSurfaceData surf   = null;

            Autodesk.Revit.DB.ElementId myEnergyModelId = null;

            //try to get the MassSurfaceData object from the document
            try
            {
                surf = (MassSurfaceData)RvtDoc.GetElement(new Autodesk.Revit.DB.ElementId(SurfaceId.InternalId));
                if (surf == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw new Exception("Couldn't find a MassSurfaceData object with Id #: " + SurfaceId.ToString());
            }

            //try to get the element id of the MassEnergyAnalyticalModel - we need this to pull faces from
            try
            {
                myEnergyModelId = surf.ReferenceElementId;
                if (myEnergyModelId == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw new Exception("Couldn't find a MassEnergyAnalyticalModel object belonging to the Mass instance with Id #: " + surf.ReferenceElementId.ToString());
            }


            //get the smallest face
            Autodesk.Revit.DB.Face smallFace = GetSmallestFace(RvtDoc, surf, myEnergyModelId);

            Autodesk.Revit.DB.Mesh prettyMesh = smallFace.Triangulate();
            return(Revit.GeometryConversion.RevitToProtoMesh.ToProtoType(prettyMesh));
        }
예제 #29
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            Reference faceRef = (args[1] as Value.Container).Item as Reference;

            Autodesk.Revit.DB.Face f = (faceRef == null) ?
                                       ((args[1] as Value.Container).Item as Autodesk.Revit.DB.Face) :
                                       dynRevitSettings.Doc.Document.GetElement(faceRef).GetGeometryObjectFromReference(faceRef) as Autodesk.Revit.DB.Face;

            XYZ norm = null;

            if (f != null)
            {
                //each item in the list will be a reference point
                UV uv = (UV)(args[0] as Value.Container).Item;
                norm = f.ComputeNormal(uv);
            }

            return(Value.NewContainer(norm));
        }
예제 #30
0
        public Face3D(RVT.Face face, ref List <string> messages)
        {
            var tolerance  = AppSettings.Instance.StoredSettings.GeometrySettings.Tolerance;
            var loops      = new List <List <Point3D> >();
            var curveLoops = face.GetEdgesAsCurveLoops();

            foreach (var cLoop in curveLoops)
            {
                var loop = new List <Point3D>();
                foreach (var curve in cLoop)
                {
                    if (curve.Length < tolerance)
                    {
                        messages.Add($"Face contains a curve that is shorter than specified tolerance of {tolerance}.");
                    }

                    var pts = GeometryUtils.GetPoints3D(curve);
                    loop.AddRange(pts);
                }

                loops.Add(loop);
            }

            var j        = 0;
            var maxArea  = 0d;
            var maxIndex = -1;

            foreach (var polygon in loops)
            {
                GetPolygonPlane(polygon.Select(x => new RVT.XYZ(x.X, x.Y, x.Z)).ToList(), out _, out _, out var area);
                if (Math.Abs(maxArea) < Math.Abs(area))
                {
                    maxIndex = j;
                    maxArea  = area;
                }
                j++;
            }

            Boundary = loops[maxIndex];
            loops.RemoveAt(maxIndex);
            Holes = loops;
        }
예제 #31
0
        private static List <PolyCurve> EdgeLoopsAsPolyCurves(Face face,
                                                              IEnumerable <IEnumerable <Edge> > edgeLoops)
        {
            List <PolyCurve> result = new List <PolyCurve>();

            foreach (var edgeLoop in edgeLoops)
            {
                List <Autodesk.DesignScript.Geometry.Curve> curves =
                    new List <Autodesk.DesignScript.Geometry.Curve>();
                foreach (var edge in edgeLoop)
                {
                    var dbCurve = edge.AsCurveFollowingFace(face);
                    curves.Add(dbCurve.ToProtoType(false));
                }
                result.Add(PolyCurve.ByJoinedCurves(curves));
                curves.ForEach(x => x.Dispose());
                curves.Clear();
            }
            return(result);
        }
예제 #32
0
 public void setConstraintFace(Autodesk.Revit.DB.Face f)
 {
     constraintFace = f;
 }
예제 #33
0
 public static Surface GetUntrimmedSurfaceFromRevitFace(Face geom,
     IEnumerable<PolyCurve> edgeLoops)
 {
     var dyFace = (dynamic)geom;
     return (Surface)SurfaceExtractor.ExtractSurface(dyFace, edgeLoops);
 }