This section illustrates how to get solids and curves from a beam. You can retrieve column and brace geometry data in a similar way. The GeometryElement may contain the desired geometry as a Solid or GeometryInstance depending on whether a beam is joined or standalone, and this code covers both cases.
The sample code is shown as follows:
Code Region 20-10: Getting solids and curves from a beam |
public void GetCurvesFromABeam(Autodesk.Revit.DB.FamilyInstance beam, Autodesk.Revit.DB.Options options) { Autodesk.Revit.DB.GeometryElement geomElem = beam.get_Geometry(options); Autodesk.Revit.DB.CurveArray curves = new CurveArray(); Autodesk.Revit.DB.SolidArray solids = new SolidArray(); //Find all solids and insert them into solid array AddCurvesAndSolids(geomElem, ref curves, ref solids); } private void AddCurvesAndSolids(Autodesk.Revit.DB.GeometryElement geomElem, ref Autodesk.Revit.DB.CurveArray curves, ref Autodesk.Revit.DB.SolidArray solids) { foreach (Autodesk.Revit.DB.GeometryObject geomObj in geomElem) { Autodesk.Revit.DB.Curve curve = geomObj as Autodesk.Revit.DB.Curve; if (null != curve) { curves.Append(curve); continue; } Autodesk.Revit.DB.Solid solid = geomObj as Autodesk.Revit.DB.Solid; if (null != solid) { solids.Append(solid); continue; } //If this GeometryObject is Instance, call AddCurvesAndSolids Autodesk.Revit.DB.GeometryInstance geomInst = geomObj as Autodesk.Revit.DB.GeometryInstance; if (null != geomInst) { Autodesk.Revit.DB.GeometryElement transformedGeomElem = geomInst.GetInstanceGeometry(geomInst.Transform); AddCurvesAndSolids(transformedGeomElem, ref curves, ref solids); } } } |
The above example uses the FamilyInstance.Geometry property to access the true geometry of the beam. To obtain the original geometry of a family instance before it is modified by joins, cuts, coping, extensions, or other post-processing, use the FamilyInstance.GetOriginalGeometry() method.