TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: EddieFromDc on December 03, 2008, 01:18:18 PM

Title: Help with "ssadd"
Post 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))
                          )     
)
)

Title: Re: Help with "ssadd"
Post by: ronjonp on December 03, 2008, 01:35:13 PM
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.
Title: Re: Help with "ssadd"
Post by: EddieFromDc on December 03, 2008, 01:50:11 PM
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.
 
Title: Re: Help with "ssadd"
Post by: VovKa on December 03, 2008, 02:32:31 PM
Code: [Select]
(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
     )
   )
)
       )
)
Title: Re: Help with "ssadd"
Post by: EddieFromDc on December 03, 2008, 02:41:01 PM
Thank you VovKa!...This is better than the "ssadd" route I was trying.
Title: Re: Help with "ssadd"
Post by: EddieFromDc on December 03, 2008, 03:19:48 PM
Vovka,

Could you please modify the code to select only blocks..Thanks!
Title: Re: Help with "ssadd"
Post by: VovKa on December 03, 2008, 03:35:46 PM
done
Title: Re: Help with "ssadd"
Post by: EddieFromDc on December 03, 2008, 03:46:10 PM
Thank you again. I should have figured that out mysel.
Title: Re: Help with "ssadd"
Post by: CAB on December 06, 2008, 08:53:35 AM
Another version that I use. Note that the extra comma is ignored by ssget.
Code: [Select]
(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))))
)
Title: Re: Help with "ssadd"
Post by: gile on December 06, 2008, 10:18:50 AM
Hi,

You can also use a (usefull) 'lst2str' function, I posted one here (http://www.theswamp.org/index.php?topic=22034.msg265916#msg265916).

Code: [Select]
(ssget "_X" (list (cons 8 (lst2str layerList))))