Beispiel #1
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);
        }
Beispiel #2
0
        /// <summary>
        /// The method is used to get extrusion's face along to the specified parameters
        /// </summary>
        /// <param name="extrusion">the extrusion</param>
        /// <param name="view">options view</param>
        /// <param name="ExtOrInt">If true indicate getting exterior extrusion face, else getting interior extrusion face</param>
        /// <returns>the face</returns>
        static public Face GetExtrusionFace(Extrusion extrusion, View view, bool ExtOrInt)
        {
            Face      face  = null;
            FaceArray faces = null;

            if (extrusion.IsSolid)
            {
                Options options = new Options();
                options.ComputeReferences = true;
                options.View = view;
                GeometryObjectArray geoArr = extrusion.get_Geometry(options).Objects;
                foreach (GeometryObject geoObj in geoArr)
                {
                    if (geoObj is Solid)
                    {
                        Solid s = geoObj as Solid;
                        faces = s.Faces;
                    }
                }
                if (ExtOrInt)
                {
                    face = GetExteriorFace(faces);
                }
                else
                {
                    face = GetInteriorFace(faces);
                }
            }
            return(face);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
0
        /// <summary>
        /// iterate GeometryObject in GeometryObjectArray and generate data accordingly
        /// </summary>
        /// <param name="objects"></param>
        /// <param name="transform"></param>
        private void AddGeometryObjects(GeometryObjectArray objects, Transform transform)
        {
            foreach (GeometryObject o in objects)
            {
                //if the type of the geometric primitive is Solid
                string geoType = o.GetType().Name;
                switch (geoType)
                {
                case "Solid":
                    AddSolid(o, transform);
                    break;

                case "Face":
                    AddFace(o, transform);
                    break;

                case "Mesh":
                    AddMesh(o, transform);
                    break;

                case "Curve":
                case "Line":
                case "Arc":
                    AddCurve(o, transform);
                    break;

                case "Profile":
                    AddProfile(o, transform);
                    break;

                case "Element":
                    AddGeoElement(o, transform);
                    break;

                case "Instance":
                    AddInstance(o, transform);
                    break;

                case "Edge":
                    AddEdge(o, transform);
                    break;

                default:
                    break;
                }
            }
        }
        /// <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);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Tessellate the curves of path reinforcement.
        /// </summary>
        private void Tessellate()
        {
            Options option = new Options();

            option.DetailLevel = DetailLevels.Fine;
            Autodesk.Revit.DB.GeometryElement geoElem = m_pathRein.get_Geometry(option);
            GeometryObjectArray geoArray = geoElem.Objects;

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

            foreach (ModelCurve modelCurve in m_pathRein.Curves)
            {
                m_path.Add(modelCurve.GeometryCurve.Tessellate() as List <XYZ>);
            }
        }
Beispiel #8
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;

            AddGeometryObjects(instanceGeometries, allTransform);
        }
Beispiel #9
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;

            foreach (object o in geoElems)
            {
                GeoSolid geoSolid = o as GeoSolid;
                if (null == geoSolid)
                {
                    continue;
                }

                return(geoSolid.Faces);
            }

            return(null);
        }
        /// <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       = DetailLevels.Medium;
            options.ComputeReferences = true;
            Autodesk.Revit.DB.GeometryElement geoElem = pathRein.get_Geometry(options);
            List <Curve>        curvesList            = new List <Curve>();
            GeometryObjectArray gObjects = geoElem.Objects;

            foreach (GeometryObject geo in gObjects)
            {
                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);
        }
Beispiel #11
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       = Autodesk.Revit.DB.DetailLevels.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)
            {
                Solid solid = obj as Solid;

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

            return(null);
        }
Beispiel #12
0
        /// <summary>
        /// find out every wall in the selection and add a dimension from the start of the wall to its end
        /// </summary>
        /// <returns>if add successfully, true will be retured, else false will be returned</returns>
        public bool AddDimension()
        {
            if (!initialize())
            {
                return(false);
            }

            Transaction transaction = new Transaction(m_revit.Application.ActiveUIDocument.Document, "Add Dimensions");

            transaction.Start();
            //get out all the walls in this array, and create a dimension from its start to its end
            for (int i = 0; i < m_walls.Count; i++)
            {
                Wall wallTemp = m_walls[i] as Wall;
                if (null == wallTemp)
                {
                    continue;
                }

                //get location curve
                Location      location     = wallTemp.Location;
                LocationCurve locationline = location as LocationCurve;
                if (null == locationline)
                {
                    continue;
                }

                //New Line
                Autodesk.Revit.DB.XYZ locationEndPoint   = locationline.Curve.get_EndPoint(1);
                Autodesk.Revit.DB.XYZ locationStartPoint = locationline.Curve.get_EndPoint(0);
                Line newLine = m_revit.Application.Application.Create.NewLine(locationStartPoint,
                                                                              locationEndPoint,
                                                                              true);

                //get reference
                ReferenceArray referenceArray = new ReferenceArray();

                Options options = m_revit.Application.Application.Create.NewGeometryOptions();
                options.ComputeReferences = true;
                options.View = m_revit.Application.ActiveUIDocument.Document.ActiveView;
                Autodesk.Revit.DB.GeometryElement element = wallTemp.get_Geometry(options);
                GeometryObjectArray geoObjectArray        = element.Objects;
                //enum the geometry element
                for (int j = 0; j < geoObjectArray.Size; j++)
                {
                    GeometryObject geoObject = geoObjectArray.get_Item(j);
                    Curve          curve     = geoObject as Curve;
                    if (null != curve)
                    {
                        //find the two upright lines beside the line
                        if (Validata(newLine, curve as Line))
                        {
                            referenceArray.Append(curve.Reference);
                        }

                        if (2 == referenceArray.Size)
                        {
                            break;
                        }
                    }
                }
                try
                {
                    //try to new a dimension
                    Autodesk.Revit.UI.UIApplication app = m_revit.Application;
                    Document doc = app.ActiveUIDocument.Document;

                    Autodesk.Revit.DB.XYZ p1 = new XYZ(
                        newLine.get_EndPoint(0).X + 5,
                        newLine.get_EndPoint(0).Y + 5,
                        newLine.get_EndPoint(0).Z);
                    Autodesk.Revit.DB.XYZ p2 = new XYZ(
                        newLine.get_EndPoint(1).X + 5,
                        newLine.get_EndPoint(1).Y + 5,
                        newLine.get_EndPoint(1).Z);

                    Line      newLine2     = app.Application.Create.NewLine(p1, p2, true);
                    Dimension newDimension = doc.Create.NewDimension(
                        doc.ActiveView, newLine2, referenceArray);
                }
                // catch the exceptions
                catch (Exception ex)
                {
                    m_errorMessage += ex.ToString();
                    return(false);
                }
            }
            m_revit.Application.ActiveUIDocument.Document.Regenerate();
            transaction.Commit();
            return(true);
        }
Beispiel #13
0
 /// <summary>
 /// iterate GeometryObject in GeometryObjectArray and generate data accordingly
 /// </summary>
 /// <param name="objects"></param>
 /// <param name="transform"></param>
 private void AddGeometryObjects(GeometryObjectArray objects, Transform transform)
 {
     foreach (GeometryObject o in objects)
     {
         //if the type of the geometric primitive is Solid
         string geoType = o.GetType().Name;
         switch (geoType)
         {
             case "Solid":
                 AddSolid(o, transform);
                 break;
             case "Face":
                 AddFace(o, transform);
                 break;
             case "Mesh":
                 AddMesh(o, transform);
                 break;
             case "Curve":
             case "Line":
             case "Arc":
                 AddCurve(o, transform);
                 break;
             case "Profile":
                 AddProfile(o, transform);
                 break;
             case "Element":
                 AddGeoElement(o, transform);
                 break;
             case "Instance":
                 AddInstance(o, transform);
                 break;
             case "Edge":
                 AddEdge(o, transform);
                 break;
             default:
                 break;
         }
     }
 }
Beispiel #14
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);
        }
Beispiel #15
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 = DetailLevels.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;

            //get all the edges in the Geometry object
            foreach (GeometryObject geo in gObjects)
            {
                //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;
                    foreach (GeometryObject objGeo in objectsGeo)
                    {
                        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);
        }