List of Layers

List of Layers

kpennell
Collaborator Collaborator
4,028 Views
7 Replies
Message 1 of 8

List of Layers

kpennell
Collaborator
Collaborator

I'm just trying to get a list of layers in a drawing to a variable, that I can manipulate and perform layer commands.

I thought (laylist) or (layerlist) functions that have been created would work, or vla-get-layers would work, but I'm not able to get the returned info to a list format.

0 Likes
Accepted solutions (1)
4,029 Views
7 Replies
Replies (7)
Message 2 of 8

rkmcswain
Mentor
Mentor
Accepted solution

Here is a nice short function to do that. 

R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 3 of 8

ВeekeeCZ
Consultant
Consultant

Or your vla-get-layers

 

(vlax-for l (vla-get-layers doc)
    (setq layers (cons (vla-get-name l) layers)))
0 Likes
Message 4 of 8

rkmcswain
Mentor
Mentor
@ВeekeeCZ wrote:
(vlax-for l (vla-get-layers doc)
(setq layers (cons (vla-get-name l) layers)))

You're missing something there. "doc" is undefined. 

R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 5 of 8

DannyNL
Advisor
Advisor

Or in your function LayerList and returns a sorted layer list Smiley Happy

 

(defun LayerList (/ LL_Return)
   (vl-sort
      (vlax-for LL_Item  (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
         (setq LL_Return (cons (vla-get-Name LL_Item) LL_Return))      
      )
      '<   
   )        
)
0 Likes
Message 6 of 8

kpennell
Collaborator
Collaborator

This one seems to do the trick.  Thanks all for the suggestions, benefits my, and everyone's learning.

0 Likes
Message 7 of 8

ВeekeeCZ
Consultant
Consultant

Of course, I am. And we all know that... Or if the OP don't, it's just a little motivation to look into help and explore things himself.

0 Likes
Message 8 of 8

scot-65
Advisor
Advisor
And one more... all together now:

;layer list [no xref or bounded xref names]
(vlax-for x (vla-get-layers *DOC*)
(if (not (wcmatch (vla-get-name x) "*|*,*$#$*"))
(setq la (cons (vla-get-name x) la))))
(setq la (vl-sort la '<))

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.