Hi,
Here's a way.
static string[] GetLayers(Layout layout, Transaction tr) =>
((BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead))
.Cast<ObjectId>()
.Select(id => (Entity)tr.GetObject(id, OpenMode.ForRead))
.GroupBy(ent => ent.Layer)
.Select(group => group.Key)
.ToArray();
static Dictionary<string, string[]> GetLayersInLayouts(Database db)
{
using (var tr = db.TransactionManager.StartOpenCloseTransaction())
{
var layoutDict = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
return layoutDict
.Cast<DictionaryEntry>()
.Select(entry => (Layout)tr.GetObject((ObjectId)entry.Value, OpenMode.ForRead))
.ToDictionary(layout => layout.LayoutName, layout => GetLayers(layout, tr));
}
}
Thanks Gill, It worked fine.
But it is getting only some layers not all layers from layout.
What layers it will not get?
Can help get all layers from the layout.
Thanks again
Rao
Now if a viewport is locked only one layer is retrieved.
I want to retrieve all layers that are set in viewport whether a viewport is locked or unlocked.
Thank you
Rao
That's different than your first request. You asked for layers in a layout, not a viewport. @_gile 's code will give you the layers of Entities on the layout. If there is only one Entity on the layout, you will only get the layer that the viewport is on. What do you want to know about layers in a viewport? Whether they are frozen or not? Or what the layers entities are using? It would be similar to running @_gile code in modelspace. But you would have to restrict it to the area contained by what the viewport sees.
I thought, all layers used in all viewports in a layout would be enumerated.
I want to know the all the non-frozen layer names used in all non-frozen viewports in layouts.
To summarize layers names and layouts names in excel
I created dll and loaded this dll in autocad.
For this I need to open Autocad and run this macro.
Is it possible to create a Windows Form app and on button press
can I get layers names and layouts names from dwg file? without opening Autocad.
Any hint please.
You can create an 'Out-of-pProcess' application (Windows Form app) but this application still need to get or create an AutoCAD process (even not Visible) to be able to read a drawing database.
See this topic.