Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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>);
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo 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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// get the faces of the mass
        /// </summary>
        /// <param name="mass">
        /// the source mass
        /// </param>
        /// <returns>
        /// the faces of the mass
        /// </returns>
        private FaceArray GetMassFaceArray(FamilyInstance mass)
        {
            // Obtain the gemotry information of the mass
            Autodesk.Revit.DB.Options opt = m_mydocument.CommandData.Application.Application.Create.NewGeometryOptions();
            opt.DetailLevel       = ViewDetailLevel.Fine;
            opt.ComputeReferences = true;
            Autodesk.Revit.DB.GeometryElement geoElement = null;
            try
            {
                geoElement = mass.get_Geometry(opt);
            }
            catch (System.Exception)
            {
                return(null);
            }

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

            //GeometryObjectArray objectarray = geoElement.Objects;
            //foreach (GeometryObject obj in objectarray)
            IEnumerator <GeometryObject> Objects = geoElement.GetEnumerator();

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

                Solid solid = obj as Solid;

                if (null != solid &&
                    null != solid.Faces &&
                    0 != solid.Faces.Size)
                {
                    return(solid.Faces);
                }
            }

            return(null);
        }
Ejemplo n.º 13
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)
            IEnumerator <GeometryObject> Objects = geoElement.GetEnumerator();

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

                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);
        }
Ejemplo 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       = ViewDetailLevel.Medium;
            options.ComputeReferences = true;
            Autodesk.Revit.DB.GeometryElement geoElem = elem.get_Geometry(options);

            //GeometryObjectArray gObjects = geoElem.Objects;
            IEnumerator <GeometryObject> Objects = geoElem.GetEnumerator();

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

                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);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// generate data of a Instance
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="transform"></param>
        private void AddInstance(GeometryObject obj, Transform transform)
        {
            GeometryInstance instance = obj as GeometryInstance;

            if (null == instance)
            {
                return;
            }
            //get a transformation of the affine 3-space
            Transform allTransform = AddTransform(transform, instance.Transform);

            GeometryElement instanceGeometry = instance.SymbolGeometry;

            if (null == instanceGeometry)
            {
                return;
            }
            //get all geometric primitives contained in the GeometryElement
            //GeometryObjectArray instanceGeometries = instanceGeometry.Objects;
            IEnumerator <GeometryObject> Objects = instanceGeometry.GetEnumerator();

            AddGeometryObjects(Objects, allTransform);
        }
Ejemplo n.º 16
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 = ViewDetailLevel.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;
            IEnumerator <GeometryObject> Objects = geoElem.GetEnumerator();

            //get all the edges in the Geometry object
            //foreach (GeometryObject geo in gObjects)
            while (Objects.MoveNext())
            {
                GeometryObject geo = Objects.Current;

                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);
        }
Ejemplo n.º 17
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)
            IEnumerator <GeometryObject> Objects = gElement.GetEnumerator();

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

                result = gObj as Solid;
                if (result != null && result.Faces.Size > 0)
                {
                    break;
                }
            }
            BoundingBoxXYZ box = elem.get_BoundingBox(null);

            return(new ElementGeometry(result, box));
        }
Ejemplo n.º 18
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;
            IEnumerator <GeometryObject> Objects = geoElement.GetEnumerator();

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

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

                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);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Get edges of element's profile
        /// </summary>
        /// <param name="elem">selected element</param>
        /// <returns>all the faces in the selected Element</returns>
        public override List <List <Edge> > GetFaces(Autodesk.Revit.DB.Element elem)
        {
            List <List <Edge> > faceEdges = new List <List <Edge> >();
            Options             options   = m_appCreator.NewGeometryOptions();

            options.DetailLevel = ViewDetailLevel.Medium;
            //make sure references to geometric objects are computed.
            options.ComputeReferences = true;
            Autodesk.Revit.DB.GeometryElement geoElem = elem.get_Geometry(options);
            //GeometryObjectArray gObjects = geoElem.Objects;
            IEnumerator <GeometryObject> Objects = geoElem.GetEnumerator();

            //get all the edges in the Geometry object
            //foreach (GeometryObject geo in gObjects)
            while (Objects.MoveNext())
            {
                GeometryObject geo = Objects.Current;

                //if beam doesn't contain opening on it, then we can get edges from instance
                //and the points we get should be transformed by instance.Tranceform
                if (geo is Autodesk.Revit.DB.GeometryInstance)
                {
                    Autodesk.Revit.DB.GeometryInstance instance = geo as Autodesk.Revit.DB.GeometryInstance;
                    m_beamTransform = instance.Transform;
                    Autodesk.Revit.DB.GeometryElement elemGeo = instance.SymbolGeometry;
                    //GeometryObjectArray objectsGeo = elemGeo.Objects;
                    IEnumerator <GeometryObject> Objects1 = elemGeo.GetEnumerator();
                    //foreach (GeometryObject objGeo in objectsGeo)
                    while (Objects1.MoveNext())
                    {
                        GeometryObject objGeo = Objects1.Current;

                        Solid solid = objGeo as Solid;
                        if (null != solid)
                        {
                            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);
                                }
                            }
                        }
                    }
                }
                //if beam contains opening on it, then we can get edges from solid
                //and the points we get do not need transform anymore
                else if (geo is Autodesk.Revit.DB.Solid)
                {
                    m_haveOpening = true;
                    Solid     solid = geo as Solid;
                    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);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="element">The host object, must be family instance</param>
        public GeometrySupport(FamilyInstance element)
        {
            // get the geometry element of the selected element
            Autodesk.Revit.DB.GeometryElement geoElement = element.get_Geometry(new Options());
            IEnumerator <GeometryObject>      Objects    = geoElement.GetEnumerator();

            //if (null == geoElement || 0 == geoElement.Objects.Size)
            if (null == geoElement || !Objects.MoveNext())
            {
                throw new Exception("Can't get the geometry of selected element.");
            }

            SweptProfile swProfile = element.GetSweptProfile();

            if (swProfile == null || !(swProfile.GetDrivingCurve() is Line))
            {
                throw new Exception("The selected element driving curve is not a line.");
            }

            // get the driving path and vector of the beam or column
            Line line = swProfile.GetDrivingCurve() as Line;

            if (null != line)
            {
                m_drivingLine   = line; // driving path
                m_drivingVector = GeomUtil.SubXYZ(line.GetEndPoint(1), line.GetEndPoint(0));
                m_drivingLength = m_drivingVector.GetLength();
            }

            //get the geometry object
            //foreach (GeometryObject geoObject in geoElement.Objects)
            Objects.Reset();
            while (Objects.MoveNext())
            {
                GeometryObject geoObject = Objects.Current;

                //get the geometry instance which contains the geometry information
                GeoInstance instance = geoObject as GeoInstance;
                if (null != instance)
                {
                    //foreach (GeometryObject o in instance.SymbolGeometry.Objects)
                    IEnumerator <GeometryObject> Objects1 = instance.SymbolGeometry.GetEnumerator();
                    while (Objects1.MoveNext())
                    {
                        GeometryObject o = Objects1.Current;

                        // get the solid of beam of column
                        Solid solid = o as Solid;

                        // do some checks.
                        if (null == solid)
                        {
                            continue;
                        }
                        if (0 == solid.Faces.Size || 0 == solid.Edges.Size)
                        {
                            continue;
                        }

                        m_solid = solid;
                        //get the transform value of instance
                        m_transform = instance.Transform;

                        // Get the swept profile curves information
                        if (!GetSweptProfile(solid))
                        {
                            throw new Exception("Can't get the swept profile curves.");
                        }
                        break;
                    }
                }
            }

            // do some checks about profile curves information
            if (null == m_edges)
            {
                throw new Exception("Can't get the geometry edge information.");
            }
            if (4 != m_points.Count)
            {
                throw new Exception("The sample only works for rectangle beam or column.");
            }
        }
Ejemplo n.º 21
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 analytical element.
            Document        document        = floor.Document;
            AnalyticalPanel analyticalModel = null;
            AnalyticalToPhysicalAssociationManager relManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document);

            if (relManager != null)
            {
                ElementId associatedElementId = relManager.GetAssociatedElementId(floor.Id);
                if (associatedElementId != ElementId.InvalidElementId)
                {
                    Element associatedElement = document.GetElement(associatedElementId);
                    if (associatedElement != null && associatedElement is AnalyticalPanel)
                    {
                        analyticalModel = associatedElement as AnalyticalPanel;
                    }
                }
            }
            if (null != analyticalModel)
            {
                IList <Curve> curveList = analyticalModel.GetOuterContour().ToList();

                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);
        }