Ejemplo n.º 1
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());
            if (null == geoElement || 0 == geoElement.Objects.Size)
            {
                throw new Exception("Can't get the geometry of selected element.");
            }

            AnalyticalModel aModel = element.GetAnalyticalModel();

            if (aModel == null)
            {
                throw new Exception("The selected FamilyInstance don't have AnalyticalModel.");
            }

            AnalyticalModelSweptProfile swProfile = aModel.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.get_EndPoint(1), line.get_EndPoint(0));
                m_drivingLength = m_drivingVector.GetLength();
            }

            //get the geometry object
            foreach (GeometryObject geoObject in geoElement.Objects)
            {
                //get the geometry instance which contains the geometry information
                GeoInstance instance = geoObject as GeoInstance;
                if (null != instance)
                {
                    foreach (GeometryObject o in instance.SymbolGeometry.Objects)
                    {
                        // 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.");
            }
        }