Author Topic: Help with "ssadd"  (Read 1961 times)

0 Members and 1 Guest are viewing this topic.

EddieFromDc

  • Newt
  • Posts: 34
Help with "ssadd"
« 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))
                          )     
)
)


ronjonp

  • Needs a day job
  • Posts: 7526
Re: Help with "ssadd"
« Reply #1 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.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

EddieFromDc

  • Newt
  • Posts: 34
Re: Help with "ssadd"
« Reply #2 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.
 

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Help with "ssadd"
« Reply #3 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
     )
   )
)
       )
)
« Last Edit: December 03, 2008, 03:33:12 PM by VovKa »

EddieFromDc

  • Newt
  • Posts: 34
Re: Help with "ssadd"
« Reply #4 on: December 03, 2008, 02:41:01 PM »
Thank you VovKa!...This is better than the "ssadd" route I was trying.

EddieFromDc

  • Newt
  • Posts: 34
Re: Help with "ssadd"
« Reply #5 on: December 03, 2008, 03:19:48 PM »
Vovka,

Could you please modify the code to select only blocks..Thanks!

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Help with "ssadd"
« Reply #6 on: December 03, 2008, 03:35:46 PM »
done

EddieFromDc

  • Newt
  • Posts: 34
Re: Help with "ssadd"
« Reply #7 on: December 03, 2008, 03:46:10 PM »
Thank you again. I should have figured that out mysel.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help with "ssadd"
« Reply #8 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))))
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Help with "ssadd"
« Reply #9 on: December 06, 2008, 10:18:50 AM »
Hi,

You can also use a (usefull) 'lst2str' function, I posted one here.

Code: [Select]
(ssget "_X" (list (cons 8 (lst2str layerList))))
Speaking English as a French Frog