TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: EddieFromDc on December 03, 2008, 01:18:18 PM
-
Hello,
I'm working with a little program to select all objects/entities on certain layers
into one selection. What I'm doing wrong?..(Layers 0, 1 & 2 have objects)..Thanks.
(defun c:test ()
(setq layerlist '("0" "1" "2" ))
(foreach n layerlist (progn
(setq ss (ssget "X" (list (cons 8 n))))
(setq s1 (ssname ss 0))
(setq sx (ssadd s1 ss))
)
)
)
-
No need to cycle through the layers...this should grab them:
(ssget "_x"
(list '(-4 . "<OR") '(-4 . "<AND") '(8 . "0") '(-4 . "AND>") '(-4 . "<AND") '(8 . "1") '(-4 . "AND>")
'(-4 . "<AND") '(8 . "2") '(-4 . "AND>") '(-4 . "OR>"))
)
I think you can also do (ssget "_x" '((8 . "1,2,3")))
but I could be wrong.
-
Ronjonp,
Thanks. But the layer list will be different most of the time.
I just tried to make it simple.
It will be a part of a bigger program wherein I have to select
all the objects whose layer property color maybe for example "red".
I can get & collect all the names of the layers whose color property
is red. And that will be my layer list.
-
(setq layerlist '("0" "1" "2"))
(setq SS
(ssget
"_X"
(list
(cons 0 "INSERT")
(cons
8
(substr
(apply
'strcat
(mapcar (function (lambda (l) (strcat "," l))) layerlist)
)
2
)
)
)
)
)
-
Thank you VovKa!...This is better than the "ssadd" route I was trying.
-
Vovka,
Could you please modify the code to select only blocks..Thanks!
-
done
-
Thank you again. I should have figured that out mysel.
-
Another version that I use. Note that the extra comma is ignored by ssget.
(defun c:test (/)
(setq layerlist '("0" "1" "2"))
(setq filter "")
(mapcar '(lambda (x) (setq filter (strcat filter x ","))) layerlist)
(setq SS (ssget "_X" (list (cons 0 "INSERT") (cons 8 filter))))
)
-
Hi,
You can also use a (usefull) 'lst2str' function, I posted one here (http://www.theswamp.org/index.php?topic=22034.msg265916#msg265916).
(ssget "_X" (list (cons 8 (lst2str layerList))))