Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create a filtered list of layer names

2 REPLIES 2
Reply
Message 1 of 3
chaddeems
410 Views, 2 Replies

Create a filtered list of layer names

I am trying to create a lisp that will return a filterd list of all the layers in the drawing. This is what i have so far:

(defun LAYERS (filter / d r)
(while (setq d (tblnext "layer" (null d)))
(if (not (wcmatch (cdr (assoc 2 d)) filter))
(setq r (cons (cdr (assoc 2 d)) r))
)
)
)

The problem i am running in to is that my layers are in 4 catagories that are AE, 1S, 2E & 3T and i can use this lisp to filter AE, 1S & 2E but it will not work for 3T. This is what it looks like:

Command: (LAYERS "1S-*")
("3T-MISC" "2E-MISC" "AE-MISC" "0")
Command: (LAYERS "2E-*")
("3T-MISC" "1S-MISC" "AE-MISC" "0")
Command: (LAYERS "3T-*")
nil
Command: (LAYERS "AE-*")
("3T-MISC" "2E-MISC" "1S-MISC" "0")

If i take the code step by step it works fine. The other problem is that if i remove the NOT before WCMATCH to return a list filtered the opposite it will not work at all. Again if i take the code piece by piece it works fine. I am done trying to figure it out. thanks

Chad
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: chaddeems

Because you are relying of the result of the (if) test, and when the final
layer matches the filter (if) returns nil. Just add the r variable to be
returned just prior to the final parenthesis.

(defun LAYERS (filter / d r)
(while (setq d (tblnext "layer" (null d)))
(if (not (wcmatch (cdr (assoc 2 d)) filter))
(setq r (cons (cdr (assoc 2 d)) r))
)
)
r
)

"chaddeems" wrote in message news:5762305@discussion.autodesk.com...
I am trying to create a lisp that will return a filterd list of all the
layers in the drawing. This is what i have so far:

(defun LAYERS (filter / d r)
(while (setq d (tblnext "layer" (null d)))
(if (not (wcmatch (cdr (assoc 2 d)) filter))
(setq r (cons (cdr (assoc 2 d)) r))
)
)
)

The problem i am running in to is that my layers are in 4 catagories that
are AE, 1S, 2E & 3T and i can use this lisp to filter AE, 1S & 2E but it
will not work for 3T. This is what it looks like:

Command: (LAYERS "1S-*")
("3T-MISC" "2E-MISC" "AE-MISC" "0")
Command: (LAYERS "2E-*")
("3T-MISC" "1S-MISC" "AE-MISC" "0")
Command: (LAYERS "3T-*")
nil
Command: (LAYERS "AE-*")
("3T-MISC" "2E-MISC" "1S-MISC" "0")

If i take the code step by step it works fine. The other problem is that if
i remove the NOT before WCMATCH to return a list filtered the opposite it
will not work at all. Again if i take the code piece by piece it works fine.
I am done trying to figure it out. thanks

Chad
Message 3 of 3
chaddeems
in reply to: chaddeems

PERFECT!!! Thanks

chad

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost