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: 

GeometryObject layer name

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
sanjaymann
1887 Views, 5 Replies

GeometryObject layer name

Hi,

 

Using the code:

foreach (GeometryObject geometryObj in dwg.get_Geometry(new Options()))
{

}

 

I can loop the objects of the linked cad file. My problem is that I want to get the layer name  of the object.

 

Thanks & Regards

Sanjay Pandey

5 REPLIES 5
Message 2 of 6
jeremytammik
in reply to: sanjaymann

Dear Sanjay,

 

Revit does not use layers.

 

I do not believe that a GeometryObject can be queried for that, or even has such a concept.

 

You might be able to open the original DWG file using AutoCAD.NET and analyse that instead.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 6
FAIR59
in reply to: sanjaymann

the information is contained in the GraphicalStyle element:

 

GraphicsStyle gStyle = document.GetElement(geometryObj.GraphicsStyleId) as GraphicsStyle;

 

layername: 

gStyle.GraphicsStyleCategory.Name

 

Message 4 of 6
sanjaymann
in reply to: FAIR59

Hi,

 

Thanks for the reply.

 

I too found the layer name the same way as you mentioned but still I will accept your answer as a solution.

 

Thanks & Regards

Sanjay Pandey

Message 5 of 6
jeremytammik
in reply to: sanjaymann

Thanks to Fair59 for the nice succinct answer. Promoted to a blog post:

 

http://thebuildingcoder.typepad.com/blog/2017/02/revitserverapilib-truss-members-and-layers.html#5

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 6 of 6
zrodgersTSSSU
in reply to: sanjaymann

@sanjaymann I am attempting to do the same thing but gstyle returns null. Any ideas?

 

 

Element elem = uidoc.Document.GetElement(elemId);

                    Options opts = app.Create.NewGeometryOptions();
                    GeometryElement geoElem = elem.get_Geometry(opts);

                    foreach(GeometryObject geoObj in geoElem)
                    {
                        GraphicsStyle gStyle = doc.GetElement(geoObj.GraphicsStyleId) as GraphicsStyle;
                        
                        if(gStyle.GraphicsStyleCategory.Name == cadLayer)
                        {
                            GeometryInstance instance = geoObj as GeometryInstance;

                            if (null != instance)
                            {
                                foreach (GeometryObject instObj in instance.SymbolGeometry)
                                {
                                    if (instObj is Curve)
                                    {
                                        ++curveCounter;
                                    }
                                    else if (instObj is PolyLine)
                                    {
                                        ++polylineCounter;
                                    }
                                }
                            }

                        }
                        
                    }

 

zrodgersTSSSU_0-1626724103642.png

 

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