Revit API - Import Instance Query

Hi all,
does anyone in here know if the Import Instance Query functionality is exposed in the Revit API? Couldn’t find it at first searchthrough… I’m especially interested in exposing the Layer/Level functionality. Or even better, maybe someone has created nodes of it? :slight_smile:

1 Like

This is how I think it works:

  • Each dwg is imported as it’s own category
  • Each layer in the dwg is a subcategory

To find the layer names you can do something like this:

4 Likes

Nice one, Einar! It seems to be extracting all the layers from the DWG rather than the ones in use, and ultimately I want to categorize element geometries by their layer. I’ll post my eventual findings here. For now I’ll mark your response as solution. :slight_smile:

Hi Jostein!

Did you find out how to categorize the element geometries by their layer? I am working on the same thing.

One can categorize element geometries by their layer by using GraphicsStyleId property of GeometryObject class.
From GraphicsStyleId one can get corresponding GraphicsStyle graphicStyle = doc.GetElement(geoObj2.GraphicsStyleId) as GraphicsStyle;
Layer name is equal to GraphicsStyleCategory name of GraphcsStyle.

Below is an example written in C#:

Document doc = this.ActiveUIDocument.Document;

FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(ImportInstance)).WhereElementIsNotElementType();
ImportInstance importInst = collector.FirstElement() as ImportInstance;

Options op = doc.Application.Create.NewGeometryOptions();
op.ComputeReferences = true;
op.IncludeNonVisibleObjects = true;

GeometryElement geoElem1 = importInst.get_Geometry(op);

if (geoElem1 != null)
{
foreach(GeometryObject geoObj1 in geoElem1)
{

GeometryInstance geoInst = geoObj1 as GeometryInstance;
                    
if(geoInst!=null)
{        	            

GeometryElement geoElem2 = geoInst.GetInstanceGeometry() as GeometryElement;
                       	
if(geoElem2!=null)
{                        	
foreach(GeometryObject geoObj2 in geoElem2)
{
if(geoObj2.GraphicsStyleId == ElementId.InvalidElementId) continue;
                            	
GraphicsStyle graphicStyle = doc.GetElement(geoObj2.GraphicsStyleId) as GraphicsStyle;
                            	
if(!layerNames.Contains(graphicStyle.GraphicsStyleCategory.Name)) continue;
                            	
if(geoObj2 is Line) lines.Add(geoObj2 as Line);

if(geoObj2 is PolyLine)polyLines.Add(geoObj2 as PolyLine);
                                
}
                           
}
}
}
}