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
Solved! Go to Solution.
Solved by FAIR59. Go to Solution.
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
the information is contained in the GraphicalStyle element:
GraphicsStyle gStyle = document.GetElement(geometryObj.GraphicsStyleId) as GraphicsStyle;
layername:
gStyle.GraphicsStyleCategory.Name
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
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
@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;
}
}
}
}
}