Layers names in layouts

Layers names in layouts

soari.do
Contributor Contributor
860 Views
10 Replies
Message 1 of 11

Layers names in layouts

soari.do
Contributor
Contributor

I am trying to extract layer names in each layout.

any suggestion, please

C#

0 Likes
861 Views
10 Replies
Replies (10)
Message 2 of 11

_gile
Consultant
Consultant

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));
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 11

1wildwes
Collaborator
Collaborator

Do you mind me asking what you're going to do with this info? And thanks to _Giles

0 Likes
Message 4 of 11

soari.do
Contributor
Contributor

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

0 Likes
Message 5 of 11

_gile
Consultant
Consultant

The method I posted gets all the layers of all entities within the BlockTableRecord of each layout.

I do not understand what you want to achieve.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 11

soari.do
Contributor
Contributor

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

0 Likes
Message 7 of 11

Ed__Jobe
Mentor
Mentor

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.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 8 of 11

soari.do
Contributor
Contributor

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.

0 Likes
Message 9 of 11

soari.do
Contributor
Contributor

I have achieved my target.

Thank you for your help

0 Likes
Message 10 of 11

soari.do
Contributor
Contributor

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.

0 Likes
Message 11 of 11

_gile
Consultant
Consultant

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.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes