/// <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."); } }
/// <summary> /// constructor /// </summary> /// <param name="element">the host object, must be family instance</param> /// <param name="geoOptions">the geometry option</param> public GeometrySupport(FamilyInstance element, Options geoOptions) { // 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)); } //get the geometry object foreach (GeometryObject geoObject in geoElement.Objects) { //get the geometry instance which contain 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 work for rectangular beams or columns."); } }