Exemplo n.º 1
1
        public JObject ConvertToDTO(Autodesk.Revit.DB.Ceiling source)
        {
            Autodesk.Revit.DB.GeometryElement defaultGeometry = source.get_Geometry(new Options());
            Solid solidGeometry = defaultGeometry.FirstOrDefault() as Solid;

            if (solidGeometry == null)
            {
                return(JObject.FromObject(new
                {
                    ERROR = 1,
                    Msg = $"Geometry does not exist for {source.Id}"
                }));
            }

            List <LMAStudio.StreamVR.Common.Models.Face> wallFaces = Helpers.GeometryConversion.ConvertToDTO(source, solidGeometry);

            LMAStudio.StreamVR.Common.Models.Ceiling dest = new LMAStudio.StreamVR.Common.Models.Ceiling
            {
                Id    = source.Id.ToString(),
                Name  = source.Name,
                Faces = wallFaces
            };

            return(JObject.FromObject(dest));
        }
Exemplo n.º 2
0
 private static void GetAllFaces(GeometryElement geoElement, List <Face> faces)
 {
     foreach (GeometryObject geObject in geoElement.Objects)
     {
         GetAllFaces(geObject, faces);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Scan GeometryElement to collect triangles.
        /// </summary>
        /// <param name="geometry">The geometry element.</param>
        /// <param name="trf">The transformation.</param>
        private void ScanGeomElement(Document document, GeometryElement geometry, Transform transform)
        {
            //get all geometric primitives contained in the GeometryElement
            foreach (GeometryObject gObject in geometry)
            {
                // if the type of the geometric primitive is Solid
                Solid solid = gObject as Solid;
                if (null != solid)
                {
                    ScanSolid(document, solid, transform);
                    continue;
                }

                // if the type of the geometric primitive is instance
                GeometryInstance instance = gObject as GeometryInstance;
                if (null != instance)
                {
                    ScanGeometryInstance(document, instance, transform);
                    continue;
                }

                GeometryElement geomElement = gObject as GeometryElement;
                if (null != geomElement)
                {
                    ScanGeomElement(document, geomElement, transform);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Located the buttom of a slab object.
        /// </summary>
        /// <param name="floor">A floor object.</param>
        /// <param name="bubbleEnd">The bubble end of new reference plane.</param>
        /// <param name="freeEnd">The free end of new reference plane.</param>
        /// <param name="thirdPnt">The third point of new reference plane.</param>
        private void LocateSlab(Floor floor, ref Autodesk.Revit.DB.XYZ bubbleEnd, ref Autodesk.Revit.DB.XYZ freeEnd, ref Autodesk.Revit.DB.XYZ thirdPnt)
        {
            //Obtain the geometry data of the floor.
            GElement geometry   = floor.get_Geometry(m_options);
            Face     buttomFace = null;

            //foreach (GeometryObject go in geometry.Objects)
            IEnumerator <GeometryObject> Objects = geometry.GetEnumerator();

            while (Objects.MoveNext())
            {
                GeometryObject go = Objects.Current;

                Solid solid = go as Solid;
                if (null == solid)
                {
                    continue;
                }
                else
                {
                    //Get the bottom face of this floor.
                    buttomFace = GeoHelper.GetBottomFace(solid.Faces);
                }
            }

            Mesh mesh = buttomFace.Triangulate();

            GeoHelper.Distribute(mesh, ref bubbleEnd, ref freeEnd, ref thirdPnt);
        }
Exemplo n.º 5
0
        /// <summary>
        /// get all planar faces of an extrusion
        /// </summary>
        /// <param name="extrusion">the extrusion to read</param>
        /// <returns>a list of all planar faces of the extrusion</returns>
        public List <PlanarFace> GetPlanarFaces(Extrusion extrusion)
        {
            // the option to get geometry elements
            Options m_geoOptions = m_application.Create.NewGeometryOptions();

            m_geoOptions.View = m_document.ActiveView;
            m_geoOptions.ComputeReferences = true;

            // get the planar faces
            List <PlanarFace> m_planarFaces = new List <PlanarFace>();

            Autodesk.Revit.DB.GeometryElement geoElement = extrusion.get_Geometry(m_geoOptions);
            //foreach (GeometryObject geoObject in geoElement.Objects)
            IEnumerator <GeometryObject> Objects = geoElement.GetEnumerator();

            while (Objects.MoveNext())
            {
                GeometryObject geoObject = Objects.Current;

                Solid geoSolid = geoObject as Solid;
                if (null == geoSolid)
                {
                    continue;
                }
                foreach (Face geoFace in geoSolid.Faces)
                {
                    if (geoFace is PlanarFace)
                    {
                        m_planarFaces.Add(geoFace as PlanarFace);
                    }
                }
            }
            return(m_planarFaces);
        }
Exemplo n.º 6
0
        const double PRECISION = 0.00001;    //precision when judge whether two doubles are equal

        /// <summary>
        /// get all faces that compose the geometry solid of given element
        /// </summary>
        /// <param name="elem">element to be calculated</param>
        /// <returns>all faces</returns>
        public static FaceArray GetFaces(Element elem)
        {
            List <Face> faces = new List <Face>();

            Autodesk.Revit.DB.Options geoOptions =
                Command.CommandData.Application.Application.Create.NewGeometryOptions();
            geoOptions.ComputeReferences = true;

            GeoElement geoElem = elem.get_Geometry(geoOptions);
            //GeometryObjectArray geoElems = geoElem.Objects;
            IEnumerator <GeometryObject> Objects = geoElem.GetEnumerator();

            //foreach (object o in geoElems)
            while (Objects.MoveNext())
            {
                object o = Objects.Current;

                GeoSolid geoSolid = o as GeoSolid;
                if (null == geoSolid)
                {
                    continue;
                }

                return(geoSolid.Faces);
            }

            return(null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// generate data of a Geometry Instance.
        /// </summary>
        /// <param name="obj">a geometry object of element.</param>
        private void AddInstance(GeometryObject obj)
        {
            Autodesk.Revit.DB.GeometryInstance instance   = obj as Autodesk.Revit.DB.GeometryInstance;
            Autodesk.Revit.DB.GeometryElement  geoElement = instance.SymbolGeometry;

            AddGeometryElement(geoElement);
        }
Exemplo n.º 8
0
        private Value GetCurvesFromFamily(Autodesk.Revit.DB.FamilyInstance fi, int count,
                                          Autodesk.Revit.DB.Options options)
        {
            FamilySymbol fs = fi.Symbol;

            //Autodesk.Revit.DB.GeometryElement geomElem = fs.get_Geometry(options);
            Autodesk.Revit.DB.GeometryElement geomElem = fi.get_Geometry(options);
            // our particular case of a loaded mass family with no joins has no geom in the instance

            //fi.GetOriginalGeometry(options);
            //fi.GetTransform()

            Autodesk.Revit.DB.CurveArray     curves    = new CurveArray();
            Autodesk.Revit.DB.ReferenceArray curveRefs = new ReferenceArray();


            //Find all curves and insert them into curve array
            AddCurves(fi, geomElem, count, ref curves);

            //curves.Append(GetCurve(fi, options)); //test

            //extract references for downstream use
            foreach (Curve c in curves)
            {
                curveRefs.Append(c.Reference);
            }

            //convert curvearray into list using Stephens MakeEnumerable
            Value result = Value.NewList(Utils.SequenceToFSharpList(
                                             dynUtils.MakeEnumerable(curves).Select(Value.NewContainer)
                                             ));


            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Tessellate the curves of path reinforcement.
        /// </summary>
        private void Tessellate()
        {
            Options option = new Options();

            option.DetailLevel = ViewDetailLevel.Fine;
            Autodesk.Revit.DB.GeometryElement geoElem = m_pathRein.get_Geometry(option);
            //GeometryObjectArray geoArray = geoElem.Objects;
            IEnumerator <GeometryObject> Objects = geoElem.GetEnumerator();

            //foreach (GeometryObject geo in geoArray)
            while (Objects.MoveNext())
            {
                GeometryObject geo = Objects.Current;

                if (geo is Curve)
                {
                    Curve curve = geo as Curve;
                    m_curves.Add(curve.Tessellate() as List <XYZ>);
                }
            }

            IList <ElementId> curveIds = m_pathRein.GetCurveElementIds();

            foreach (ElementId id in curveIds)
            {
                ModelCurve modelCurve = m_commandData.Application.ActiveUIDocument.Document.GetElement(id) as ModelCurve;
                m_path.Add(modelCurve.GeometryCurve.Tessellate() as List <XYZ>);
            }
        }
Exemplo n.º 10
0
 private static void GetAllCurves(GeometryElement geoElement, List <Curve> curves)
 {
     foreach (GeometryObject geObject in geoElement.Objects)
     {
         GetAllCurves(geObject, curves);
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Get an edge from the form by its endpoints
        /// </summary>
        /// <param name="form">The form contains the edge</param>
        /// <param name="startPoint">Start point of the edge</param>
        /// <param name="endPoint">End point of the edge</param>
        /// <returns>The edge found</returns>
        private Edge GetEdgeByEndPoints(Form form, Autodesk.Revit.DB.XYZ startPoint, Autodesk.Revit.DB.XYZ endPoint)
        {
            Edge edge = null;

            // Get all edges of the form
            EdgeArray edges      = null;
            Options   geoOptions = m_revitApp.Create.NewGeometryOptions();

            geoOptions.ComputeReferences = true;
            Autodesk.Revit.DB.GeometryElement geoElement = form.get_Geometry(geoOptions);
            foreach (GeometryObject geoObject in geoElement.Objects)
            {
                Solid solid = geoObject as Solid;
                if (null == solid)
                {
                    continue;
                }
                edges = solid.Edges;
            }

            // Traverse the edges and look for the edge with the right endpoints
            foreach (Edge ed in edges)
            {
                Autodesk.Revit.DB.XYZ rpPos1 = ed.Evaluate(0);
                Autodesk.Revit.DB.XYZ rpPos2 = ed.Evaluate(1);
                if ((startPoint.IsAlmostEqualTo(rpPos1) && endPoint.IsAlmostEqualTo(rpPos2)) ||
                    (startPoint.IsAlmostEqualTo(rpPos2) && endPoint.IsAlmostEqualTo(rpPos1)))
                {
                    edge = ed;
                    break;
                }
            }

            return(edge);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Get geometry of the pathReinforcement
        /// </summary>
        /// <param name="pathRein">pathReinforcement created</param>
        private List <List <XYZ> > GetGeometry(PathReinforcement pathRein)
        {
            Options options = m_profile.CommandData.Application.Application.Create.NewGeometryOptions();

            options.DetailLevel       = ViewDetailLevel.Medium;
            options.ComputeReferences = true;
            Autodesk.Revit.DB.GeometryElement geoElem = pathRein.get_Geometry(options);
            List <Curve> curvesList = new List <Curve>();
            //GeometryObjectArray gObjects = geoElem.Objects;
            IEnumerator <GeometryObject> Objects = geoElem.GetEnumerator();

            //foreach (GeometryObject geo in gObjects)
            while (Objects.MoveNext())
            {
                GeometryObject geo = Objects.Current;

                Curve curve = geo as Curve;
                curvesList.Add(curve);
            }
            List <List <XYZ> > pointsPreview = new List <List <XYZ> >();

            foreach (Curve curve in curvesList)
            {
                pointsPreview.Add(curve.Tessellate() as List <XYZ>);
            }
            return(pointsPreview);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Get all points of the Slab
        /// </summary>
        /// <returns>points array stores all the points on slab</returns>
        public EdgeArray GetFloorEdges()
        {
            EdgeArray edges   = new EdgeArray();
            Options   options = m_commandData.Application.Application.Create.NewGeometryOptions();

            options.DetailLevel = DetailLevels.Medium;
            //make sure references to geometric objects are computed.
            options.ComputeReferences = true;
            Autodesk.Revit.DB.GeometryElement geoElem = m_floor.get_Geometry(options);
            GeometryObjectArray gObjects = geoElem.Objects;

            //get all the edges in the Geometry object
            foreach (GeometryObject geo in gObjects)
            {
                Solid solid = geo as Solid;
                if (solid != null)
                {
                    FaceArray faces = solid.Faces;
                    foreach (Face face in faces)
                    {
                        EdgeArrayArray edgeArrarr = face.EdgeLoops;
                        foreach (EdgeArray edgeArr in edgeArrarr)
                        {
                            foreach (Edge edge in edgeArr)
                            {
                                edges.Append(edge);
                            }
                        }
                    }
                }
            }
            return(edges);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Get edges of element's profile
        /// </summary>
        /// <param name="elem">Selected element</param>
        public List <List <Edge> > GetFaces(Autodesk.Revit.DB.Element elem)
        {
            List <List <Edge> > faceEdges = new List <List <Edge> >();
            Options             options   = m_appCreator.NewGeometryOptions();

            options.DetailLevel       = DetailLevels.Medium;
            options.ComputeReferences = true;
            Autodesk.Revit.DB.GeometryElement geoElem = elem.get_Geometry(options);

            GeometryObjectArray gObjects = geoElem.Objects;

            foreach (GeometryObject geo in gObjects)
            {
                Solid solid = geo as Solid;
                if (solid != null)
                {
                    EdgeArray edges = solid.Edges;
                    FaceArray faces = solid.Faces;
                    foreach (Face face in faces)
                    {
                        EdgeArrayArray edgeArrarr = face.EdgeLoops;
                        foreach (EdgeArray edgeArr in edgeArrarr)
                        {
                            List <Edge> edgesList = new List <Edge>();
                            foreach (Edge edge in edgeArr)
                            {
                                edgesList.Add(edge);
                            }
                            faceEdges.Add(edgesList);
                        }
                    }
                }
            }
            return(faceEdges);
        }
        void GetSelectedRevitElements(UIDocument uidoc)
        {
            Selection selection = uidoc.Selection;
            ICollection <ElementId> selectedIds = uidoc.Selection.GetElementIds();

            //outVals.Add("Num Selection: " + selectedIds.Count.ToString());
            ghbreps = new List <GH_Brep>();
            foreach (ElementId id in selectedIds)
            {
                Autodesk.Revit.DB.Options         opt      = new Options();
                Autodesk.Revit.DB.GeometryElement geomElem = uidoc.Document.GetElement(id).get_Geometry(opt);

                //outVals.Add("Num Geo: " + geomElem.Count().ToString());
                foreach (GeometryObject geomObj in geomElem)
                {
                    var facePtList = new List <List <Point3d> >();

                    Solid geomSolid = geomObj as Solid;
                    var   breps     = geomSolid.ToRhino();
                    foreach (var item in breps)
                    {
                        var ghB = new GH_Brep(item);

                        ghbreps.Add(ghB);
                    }


                    //outputs = facePtList;
                }


                //TaskDialog.Show("Revit", faceInfo);
                //ids.Add(id.IntegerValue);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Compute the area of the curtain panel instance
        /// </summary>
        /// <param name="familyinstance">
        /// the curtain panel which needs to be computed
        /// </param>
        /// <returns>
        /// the area of the curtain panel
        /// </returns>
        private double GetAreaOfTileInstance(FamilyInstance familyinstance)
        {
            double panelArea = 0d;

            Autodesk.Revit.DB.Options opt = m_uiApp.Application.Create.NewGeometryOptions();
            opt.ComputeReferences = true;
            Autodesk.Revit.DB.GeometryElement geomElem = familyinstance.get_Geometry(opt);
            //foreach (GeometryObject geomObject1 in geomElem.Objects)
            IEnumerator <GeometryObject> Objects = geomElem.GetEnumerator();

            while (Objects.MoveNext())
            {
                GeometryObject geomObject1 = Objects.Current;

                Solid solid = null;
                // find area of partial border panels
                if (geomObject1 is Solid)
                {
                    solid = (Solid)geomObject1;
                    if (null == solid)
                    {
                        continue;
                    }
                }
                // find area of non-partial panels
                else if (geomObject1 is GeometryInstance)
                {
                    GeometryInstance geomInst = geomObject1 as GeometryInstance;
                    //foreach (Object geomObj in geomInst.SymbolGeometry.Objects)
                    IEnumerator <GeometryObject> Objects1 = geomInst.SymbolGeometry.GetEnumerator();
                    while (Objects1.MoveNext())
                    {
                        Object geomObj = Objects1.Current;

                        solid = geomObj as Solid;
                        if (solid != null)
                        {
                            break;
                        }
                    }
                }

                if (null == solid.Faces || 0 == solid.Faces.Size)
                {
                    continue;
                }

                // get the area and write the data to a text file
                foreach (Face face in solid.Faces)
                {
                    panelArea = face.Area;
                    m_writeFile.WriteLine(familyinstance.Id.IntegerValue + " : " + panelArea);
                }
            }
            return(panelArea);
        }
Exemplo n.º 17
0
        public JObject ConvertToDTO(Autodesk.Revit.DB.Wall source)
        {
            Autodesk.Revit.DB.Curve curve = (source.Location as LocationCurve).Curve;
            Autodesk.Revit.DB.Line  line  = curve as Autodesk.Revit.DB.Line;

            if (line == null)
            {
                return(null);
            }

            BoundingBoxXYZ bb = source.get_BoundingBox(null);

            Autodesk.Revit.DB.XYZ origin   = line.Tessellate().First();
            Autodesk.Revit.DB.XYZ endpoint = line.Tessellate().Last(); /// origin + line.Direction * line.Length;

            List <LMAStudio.StreamVR.Common.Models.Face> wallFaces = new List <LMAStudio.StreamVR.Common.Models.Face>();

            Autodesk.Revit.DB.GeometryElement defaultGeometry = source.get_Geometry(new Options());
            if (defaultGeometry != null)
            {
                Solid solidGeometry = defaultGeometry.FirstOrDefault() as Solid;

                if (solidGeometry != null)
                {
                    wallFaces = GeometryConversion.ConvertToDTO(source, solidGeometry);
                }
            }

            LMAStudio.StreamVR.Common.Models.Wall dest = new LMAStudio.StreamVR.Common.Models.Wall
            {
                Id          = source.Id.ToString(),
                Name        = source.Name,
                Depth       = source.Width,
                Orientation = new LMAStudio.StreamVR.Common.Models.XYZ
                {
                    X = source.Orientation.X,
                    Y = source.Orientation.Y,
                    Z = source.Orientation.Z,
                },
                Endpoint0 = new LMAStudio.StreamVR.Common.Models.XYZ
                {
                    X = origin.X,
                    Y = origin.Y,
                    Z = bb.Min.Z,
                },
                Endpoint1 = new LMAStudio.StreamVR.Common.Models.XYZ
                {
                    X = endpoint.X,
                    Y = endpoint.Y,
                    Z = bb.Max.Z,
                },
                Faces = wallFaces
            };

            return(JObject.FromObject(dest));
        }
Exemplo n.º 18
0
        /// <summary>
        /// construct function.
        /// </summary>
        /// <param name="door">of which geometry data is wanted.</param>
        public DoorGeometry(Autodesk.Revit.DB.Element door)
        {
            m_options      = new Options();
            m_options.View = GetPlanform2DView(door);
            m_options.ComputeReferences = false;
            Autodesk.Revit.DB.GeometryElement geoEle = door.get_Geometry(m_options);
            AddGeometryElement(geoEle);

            m_bbox = door.get_BoundingBox(m_options.View);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Removes all painted faces on an elementl
        /// </summary>
        /// <param name="Element">The element to removve painted faces</param>
        /// <returns name="Element">The modified element</returns>
        public static DynaElem RemovePaintElement(DynaElem Element)
        {
            string transactionName = "Remove Painted Faces of Element";

            RevitDoc    document  = Element.InternalElement.Document;
            RevitElemId elementId = Element.InternalElement.Id;

            RevitDB.Options         op      = new RevitDB.Options();
            RevitDB.GeometryElement geoElem = Element.InternalElement.get_Geometry(op);

            IList <RevitDB.Face> faces = new List <RevitDB.Face>();

            foreach (RevitDB.GeometryObject geo in geoElem)
            {
                if (geo is RevitDB.Solid)
                {
                    RevitDB.Solid solid = geo as RevitDB.Solid;
                    foreach (RevitDB.Face face in solid.Faces)
                    {
                        faces.Add(face);
                    }
                }
                else if (geo is RevitDB.Face)
                {
                    faces.Add(geo as RevitDB.Face);
                }

                Action <RevitElemId, IList <RevitDB.Face> > RemovePaintedFaces = (RevitElemId elemId, IList <RevitDB.Face> faceList) =>
                {
                    foreach (RevitDB.Face face in faceList)
                    {
                        document.RemovePaint(elemId, face);
                    }
                };

                if (document.IsModifiable)
                {
                    TransactionManager.Instance.EnsureInTransaction(document);
                    RemovePaintedFaces(elementId, faces);
                    TransactionManager.Instance.TransactionTaskDone();
                }
                else
                {
                    using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document))
                    {
                        trans.Start(transactionName);
                        RemovePaintedFaces(elementId, faces);
                        trans.Commit();
                    }
                }
            }

            return(Element);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Get a floor's profile.
        /// </summary>
        /// <param name="floor">The floor whose profile you want to get.</param>
        /// <returns>The profile of the floor.</returns>
        private CurveArray GetFloorProfile(Floor floor)
        {
            CurveArray floorProfile = new CurveArray();

            // Structural slab's profile can be found in it's AnalyticalModel.
            if (null != floor.GetAnalyticalModel())
            {
                AnalyticalModel analyticalModel = floor.GetAnalyticalModel();
                IList <Curve>   curveList       = analyticalModel.GetCurves(AnalyticalCurveType.ActiveCurves);
                for (int i = 0; i < curveList.Count; i++)
                {
                    floorProfile.Append(curveList[i]);
                }

                return(floorProfile);
            }

            // Nonstructural floor's profile can be formed through it's Geometry.
            Options aOptions = m_revit.Application.Create.NewGeometryOptions();

            Autodesk.Revit.DB.GeometryElement aElementOfGeometry = floor.get_Geometry(aOptions);
            //GeometryObjectArray geometryObjects = aElementOfGeometry.Objects;
            IEnumerator <GeometryObject> Objects = aElementOfGeometry.GetEnumerator();

            //foreach (GeometryObject o in geometryObjects)
            while (Objects.MoveNext())
            {
                GeometryObject o = Objects.Current;

                Solid solid = o as Solid;
                if (null == solid)
                {
                    continue;
                }

                // Form the floor's profile through solid's edges.
                EdgeArray edges = solid.Edges;
                for (int i = 0; i < (edges.Size) / 3; i++)
                {
                    Edge       edge     = edges.get_Item(i);
                    List <XYZ> xyzArray = edge.Tessellate() as List <XYZ>; // A set of points.
                    for (int j = 0; j < (xyzArray.Count - 1); j++)
                    {
                        Autodesk.Revit.DB.XYZ startPoint = xyzArray[j];
                        Autodesk.Revit.DB.XYZ endPoint   = xyzArray[j + 1];
                        Line line = Line.CreateBound(startPoint, endPoint);

                        floorProfile.Append(line);
                    }
                }
            }
            return(floorProfile);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Get all the edges from the given family instance
        /// </summary>
        /// <param name="familyInstance">The family instance with some edges</param>
        /// <returns>Edges of the family instance</returns>
        private EdgeArray GetEdges(FamilyInstance familyInstance)
        {
            Autodesk.Revit.DB.Options opt = m_app.Create.NewGeometryOptions();
            opt.ComputeReferences = true;
            Autodesk.Revit.DB.GeometryElement geomElem = familyInstance.get_Geometry(opt);
            //foreach (GeometryObject geomObject1 in geomElem.Objects)
            IEnumerator <GeometryObject> Objects = geomElem.GetEnumerator();

            while (Objects.MoveNext())
            {
                GeometryObject geomObject1 = Objects.Current;

                Solid solid = null;
                // partial panels
                if (geomObject1 is Solid)
                {
                    solid = (Solid)geomObject1;
                    if (null == solid)
                    {
                        continue;
                    }
                }
                // non-partial panels
                else if (geomObject1 is Autodesk.Revit.DB.GeometryInstance)
                {
                    GeometryInstance geomInst = geomObject1 as GeometryInstance;
                    //foreach (Object geomObj in geomInst.SymbolGeometry.Objects)
                    IEnumerator <GeometryObject> Objects1 = geomInst.SymbolGeometry.GetEnumerator();
                    while (Objects1.MoveNext())
                    {
                        Object geomObj = Objects1.Current;

                        solid = geomObj as Solid;
                        if (solid != null)
                        {
                            break;
                        }
                    }
                }

                if (null == solid ||                                                                          // the solid can't be null
                    null == solid.Faces || 0 == solid.Faces.Size ||                                           // the solid must have 1 or more faces
                    null == solid.Faces.get_Item(0) ||                                                        // the solid must have a NOT-null face
                    null == solid.Faces.get_Item(0).EdgeLoops || 0 == solid.Faces.get_Item(0).EdgeLoops.Size) // the face must have some edges
                {
                    continue;
                }

                return(solid.Faces.get_Item(0).EdgeLoops.get_Item(0));
            }

            return(null);
        }
Exemplo n.º 22
0
        private static void GetAllFaces(GeometryElement geoElement, List <Face> faces)
        {
            //foreach (GeometryObject geObject in geoElement.Objects)
            IEnumerator <GeometryObject> Objects = geoElement.GetEnumerator();

            while (Objects.MoveNext())
            {
                GeometryObject geObject = Objects.Current;

                GetAllFaces(geObject, faces);
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// get the solids in a Geometric primitive
        /// </summary>
        /// <param name="obj">a geometry object of element</param>
        /// <param name="transform"></param>
        private void AddGeoElement(GeometryObject obj, Transform transform)
        {
            GeometryElement geometry = obj as GeometryElement;

            if (null == geometry)
            {
                return;
            }

            //get all geometric primitives contained in the GeometryElement
            GeometryObjectArray geometries = geometry.Objects;

            AddGeometryObjects(geometries, transform);
        }
Exemplo n.º 24
0
        /// <summary>
        /// get the solids in a Geometric primitive
        /// </summary>
        /// <param name="obj">a geometry object of element</param>
        /// <param name="transform"></param>
        private void AddGeoElement(GeometryObject obj, Transform transform)
        {
            GeometryElement geometry = obj as GeometryElement;

            if (null == geometry)
            {
                return;
            }

            //get all geometric primitives contained in the GeometryElement
            IEnumerator <GeometryObject> Objects = geometry.GetEnumerator();

            AddGeometryObjects(Objects, transform);
        }
Exemplo n.º 25
0
      /// <summary>
      /// Judge whether an element has face geometry
      /// </summary>
      /// <param name="elem">the element to be checked</param>
      /// <returns>true is having face geometry, false is having no face geometry</returns>
      private bool CheckSelectedElement(RevitElement elem)
      {
         if (null == elem)
         {
            return false;
         }
         Autodesk.Revit.DB.Options opts = new Autodesk.Revit.DB.Options();
         opts.View = m_revitDoc.Document.ActiveView;
         opts.ComputeReferences = true;
         // Get geometry of the element
         GeoElement geoElement = elem.get_Geometry(opts);
         InquireGeometry(geoElement, elem);

         return true;
      }
Exemplo n.º 26
0
        /// <summary>
        /// create 3D and 2D data of given GeometryElement
        /// </summary>
        /// <param name="elem">of which geometry data be gotten</param>
        /// <param name="currentView">current view of Revit</param>
        public GeometryData(Element elem, View currentView)
        {
            Options opt = Command.CommandData.Application.Application.Create.NewGeometryOptions();

            opt.View = currentView;
            opt.ComputeReferences = false;
            GeometryElement geoElement = elem.get_Geometry(opt);

            Autodesk.Revit.DB.XYZ xyz       = new Autodesk.Revit.DB.XYZ(0, 0, 0);
            Transform             transform = Transform.CreateTranslation(xyz);

            AddGeoElement(geoElement, transform);

            m_bbox = elem.get_BoundingBox(currentView);
        }
Exemplo n.º 27
0
        public IEnumerable <Autodesk.Revit.DB.GeometryObject> InternalGeometry()
        {
            var thisElement = InternalElement;

            var instanceGeometryObjects = new List <Autodesk.Revit.DB.GeometryObject>();

            var geoOptionsOne = new Autodesk.Revit.DB.Options();

            geoOptionsOne.ComputeReferences = true;

            var geomObj     = thisElement.get_Geometry(geoOptionsOne);
            var geomElement = geomObj as GeometryElement;

            if ((thisElement is GenericForm) && (geomElement.Count() < 1))
            {
                var gF = (GenericForm)thisElement;
                if (!gF.Combinations.IsEmpty)
                {
                    var geoOptionsTwo = new Autodesk.Revit.DB.Options();
                    geoOptionsTwo.IncludeNonVisibleObjects = true;
                    geoOptionsTwo.ComputeReferences        = true;
                    geomObj     = thisElement.get_Geometry(geoOptionsTwo);
                    geomElement = geomObj as GeometryElement;
                }
            }

            foreach (Autodesk.Revit.DB.GeometryObject geob in geomElement)
            {
                var ginsta = geob as GeometryInstance;
                if (ginsta != null)
                {
                    Autodesk.Revit.DB.GeometryElement instanceGeom = ginsta.GetInstanceGeometry();
                    instanceGeometryObjects.Add(instanceGeom);
                    foreach (Autodesk.Revit.DB.GeometryObject geobInst in instanceGeom)
                    {
                        instanceGeometryObjects.Add(geobInst);
                    }
                }
                else
                {
                    instanceGeometryObjects.Add(geob);
                }
            }

            return(instanceGeometryObjects);
        }
Exemplo n.º 28
0
        /// <summary>
        /// iterate GeometryObject in GeometryObjectArray and generate data accordingly.
        /// </summary>
        /// <param name="geoEle">a geometry object of element</param>
        private void AddGeometryElement(Autodesk.Revit.DB.GeometryElement geoEle)
        {
            // get all geometric primitives contained in the Geometry Element
            //GeometryObjectArray geoObjArray = geoEle.Objects;
            IEnumerator <GeometryObject> Objects = geoEle.GetEnumerator();

            // iterate each Geometry Object and generate data accordingly.
            //foreach (GeometryObject geoObj in geoObjArray)
            while (Objects.MoveNext())
            {
                GeometryObject geoObj = Objects.Current;

                if (geoObj is Curve)
                {
                    AddCurve(geoObj);
                }
                else if (geoObj is Edge)
                {
                    AddEdge(geoObj);
                }
                else if (geoObj is Autodesk.Revit.DB.GeometryElement)
                {
                    AddElement(geoObj);
                }
                else if (geoObj is Face)
                {
                    AddFace(geoObj);
                }
                else if (geoObj is Autodesk.Revit.DB.GeometryInstance)
                {
                    AddInstance(geoObj);
                }
                else if (geoObj is Mesh)
                {
                    AddMesh(geoObj);
                }
                else if (geoObj is Profile)
                {
                    AddProfile(geoObj);
                }
                else if (geoObj is Solid)
                {
                    AddSolid(geoObj);
                }
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Extract the geometry of the given Element.
        /// </summary>
        /// <param name="elem">Element parameter</param>
        /// <returns>Element's geometry</returns>
        protected ElementGeometry ExtractGeom(Autodesk.Revit.DB.Element elem)
        {
            Solid   result  = null;
            Options options = new Options();

            options.ComputeReferences = true;
            Autodesk.Revit.DB.GeometryElement gElement = elem.get_Geometry(options);
            foreach (GeometryObject gObj in gElement.Objects)
            {
                result = gObj as Solid;
                if (result != null && result.Faces.Size > 0)
                {
                    break;
                }
            }
            BoundingBoxXYZ box = elem.get_BoundingBox(null);

            return(new ElementGeometry(result, box));
        }
Exemplo n.º 30
0
        /// <summary>
        /// iterate GeometryObject in GeometryObjectArray and generate data accordingly.
        /// </summary>
        /// <param name="geoEle">a geometry object of element</param>
        private void AddGeometryElement(Autodesk.Revit.DB.GeometryElement geoEle)
        {
            // get all geometric primitives contained in the Geometry Element
            GeometryObjectArray geoObjArray = geoEle.Objects;

            // iterate each Geometry Object and generate data accordingly.
            foreach (GeometryObject geoObj in geoObjArray)
            {
                if (geoObj is Curve)
                {
                    AddCurve(geoObj);
                }
                else if (geoObj is Edge)
                {
                    AddEdge(geoObj);
                }
                else if (geoObj is Autodesk.Revit.DB.GeometryElement)
                {
                    AddElement(geoObj);
                }
                else if (geoObj is Face)
                {
                    AddFace(geoObj);
                }
                else if (geoObj is Autodesk.Revit.DB.GeometryInstance)
                {
                    AddInstance(geoObj);
                }
                else if (geoObj is Mesh)
                {
                    AddMesh(geoObj);
                }
                else if (geoObj is Profile)
                {
                    AddProfile(geoObj);
                }
                else if (geoObj is Solid)
                {
                    AddSolid(geoObj);
                }
            }
        }
Exemplo n.º 31
0
 private static void GetAllFaces(GeometryElement geoElement, List<Face> faces)
 {
     foreach (GeometryObject geObject in geoElement.Objects)
     {
         GetAllFaces(geObject, faces);
     }
 }
Exemplo n.º 32
0
 private static void GetAllCurves(GeometryElement geoElement, List<Curve> curves)
 {
     foreach (GeometryObject geObject in geoElement.Objects)
     {
         GetAllCurves(geObject, curves);
     }
 }
Exemplo n.º 33
0
        /// <summary>
        /// Inquire an geometry element to get all face instances
        /// </summary>
        /// <param name="geoElement">the geometry element</param>
        /// <param name="elem">the element, it provides the prefix of face name</param>
        /// <returns></returns>
        private bool InquireGeometry(GeoElement geoElement, RevitElement elem)
        {
            if(null == geoElement || null == elem)
            {
                return false;
            }

            GeometryObjectArray geoArray = null;

            if (null != geoElement && null != geoElement.Objects)
            {
                geoArray = geoElement.Objects;
            }
            else
            {
                return false;
            }

            foreach (GeometryObject obj in geoArray)
            {
                if (obj is GeoInstance)
                {
                    GeoInstance instance = (GeoInstance)obj;
                    InquireGeometry(instance.SymbolGeometry, elem);
                }
                else if (!(obj is Solid))
                {
                    // is not Solid instance
                    continue;
                }

                // continue when obj is Solid instance
                Solid solid = obj as Solid;
                if (null == solid)
                {
                    continue;
                }
                FaceArray faces = solid.Faces;
                if (faces.IsEmpty)
                {
                    continue;
                }

                // get the face name list
                String category = String.Empty;
                if (null != elem.Category && null != elem.Name)
                {
                    category = elem.Category.Name;
                }

                int ii = 0;
                foreach (Face tempFace in faces)
                {
                    if (tempFace is PlanarFace)
                    {
                        m_faceNameList.Add(
                            String.Format("{0} : {1} ({2})", category, elem.Name, ii));
                        m_faceList.Add(tempFace);
                        ii++;
                    }
                }
            }
            return true;
        }
        /// <summary>
        /// Scan GeometryElement to collect triangles.
        /// </summary>
        /// <param name="geometry">The geometry element.</param>
        /// <param name="trf">The transformation.</param>
        private void ScanGeomElement(Document document, GeometryElement geometry, Transform transform)
        {
            //get all geometric primitives contained in the GeometryElement
            foreach (GeometryObject gObject in geometry)
            {
                // if the type of the geometric primitive is Solid
                Solid solid = gObject as Solid;
                if (null != solid)
                {
                    ScanSolid(document,solid, transform);
                    continue;
                }

                // if the type of the geometric primitive is instance
                GeometryInstance instance = gObject as GeometryInstance;
                if (null != instance)
                {
                    ScanGeometryInstance(document, instance, transform);
                    continue;
                }

                GeometryElement geomElement = gObject as GeometryElement;
                if (null != geomElement)
                {
                    ScanGeomElement(document,geomElement, transform);
                }
            }
        }