GeometryObject layer name

GeometryObject layer name

Anonymous
Not applicable
2,554 Views
5 Replies
Message 1 of 6

GeometryObject layer name

Anonymous
Not applicable

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

0 Likes
Accepted solutions (1)
2,555 Views
5 Replies
Replies (5)
Message 2 of 6

jeremytammik
Autodesk
Autodesk

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

0 Likes
Message 3 of 6

FAIR59
Advisor
Advisor
Accepted solution

the information is contained in the GraphicalStyle element:

 

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

 

layername: 

gStyle.GraphicsStyleCategory.Name

 

Message 4 of 6

Anonymous
Not applicable

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

0 Likes
Message 5 of 6

jeremytammik
Autodesk
Autodesk

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

0 Likes
Message 6 of 6

zrodgersTSSSU
Advocate
Advocate

@Anonymous 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

 

0 Likes