ElementGeometry Property |
This call will retrieve 3d representation of the element. will be returned for symbols, annotations or details. This involves extensive parsing or Revit's data structures, so try to minimize calls if performance is critical.
Geometry objects provided from this method are obtained directly from the element. When the element is changed for any reason, the geometry will be recalculated by Revit and geometry objects obtained before the change are likely to no longer be valid. If you need to preserve geometry information obtained an element even after changes to that element, you should copy the geometry objects or save the properties independently.
Although the geometry obtained from this method comes directly from the element, any attempt to modify any of the geometry objects will operate only on a disconnected copy of the original geometry object from the element. The modification will not affect the geometry of the original element from which it was obtained - to change the geometry of the element you must use methods that directly affect the geometry calculated or stored by Revit for this element.
If you require that the geometry items obtained contain valid Reference objects, be sure to set the ComputeReferences property of the Options.
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(); System.Collections.Generic.List<Autodesk.Revit.DB.Solid> solids = new System.Collections.Generic.List<Autodesk.Revit.DB.Solid>(); //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 System.Collections.Generic.List<Autodesk.Revit.DB.Solid> 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.Add(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); } } }