Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Retrieving all elements

2 REPLIES 2
Reply
Message 1 of 3
Sigvald
17181 Views, 2 Replies

Retrieving all elements

Hey !

 

I have to retrieve all elements from the document (without the need of a user selection) to get all information about Face, Mesh, Vertex... I have to export those data to a rendering engine. I have no idea how to do that and the only exemples I found are about getting data from a selected element.

 

Best !

2 REPLIES 2
Message 2 of 3
adam.nagy
in reply to: Sigvald

Hi there,

 

This should help to get back "all" the elements: http://thebuildingcoder.typepad.com/blog/2010/06/filter-for-all-elements.html

 

But actually it seems you only need the visible elements:

 

IList<Element> GetAllModelElements( Document doc )
{
  List<Element> elements = new List<Element>();
 
  FilteredElementCollector collector
    = new FilteredElementCollector( doc )
      .WhereElementIsNotElementType();
 
  foreach( Element e in collector )
  {
    if( null != e.Category
      && e.Category.HasMaterialQuantities )
    {
      elements.Add( e );
    }
  }
  return elements;
}

Then you need to retrieve the geometry from each element you are interested in.

 

There are many topics on Jeremy's blog concerning this: http://thebuildingcoder.typepad.com/blog/2010/01/analyse-building-geometry.html

 

I hope this helps.

 

Adam Nagy

Autodesk Developer Network



Adam Nagy
Autodesk Platform Services
Message 3 of 3
Sigvald
in reply to: adam.nagy

It works, thank you so much !

 

But I'm not sure that I'm using it correctly. Here is my code:

UIApplication uiApplication = cmdData.Application;
                UIDocument uiDocument = uiApplication.ActiveUIDocument;

                List<double> listData = new List<double>();

                Options geoOptions = uiApplication.Application.Create.NewGeometryOptions();
                if (geoOptions != null)
                {
                    geoOptions.ComputeReferences = true;
                    geoOptions.DetailLevel = DetailLevels.Fine;
                }
                List<Element> elements = new List<Element>();
                FilteredElementCollector collector = new FilteredElementCollector(uiDocument.Document).WhereElementIsNotElementType();
                foreach (Element e in collector)
                {
                    if (e.Category != null && e.Category.HasMaterialQuantities)
                    {
                        elements.Add(e);
                    }
                }
                foreach (Element elem in elements)
                {
                    GeometryElement geoElement = elem.get_Geometry(geoOptions);
                    // Get geometry object
                    foreach (GeometryObject geoObject in geoElement.Objects)
                    {
                        // Get the geometry instance which contains the geometry information
                        GeometryInstance geometryInstance = geoObject as GeometryInstance;
                        if (geometryInstance != null)
                        {
                            foreach (GeometryObject instObj in geometryInstance.SymbolGeometry.Objects)
                            {
                                Solid solid = instObj as Solid;
                                if (solid == null || solid.Faces.Size == 0)
                                {
                                    continue;
                                }
                                Transform transform = geometryInstance.Transform;

                                // Get the faces from solid
                                foreach (Face face in solid.Faces)
                                {
                                    Mesh mesh = face.Triangulate();
                                    foreach (XYZ point in mesh.Vertices)
                                    {
                                        listData.Add(point.X);
                                        listData.Add(point.Y);
                                        listData.Add(point.Z);
                                    }
                                }
                            }
                        }
                    }
                }

 

What about getting information about the Transformation ?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community