Lisp to select all element in the layer 123

Lisp to select all element in the layer 123

karthikeyanskm
Contributor Contributor
568 Views
4 Replies
Message 1 of 5

Lisp to select all element in the layer 123

karthikeyanskm
Contributor
Contributor

(defun c:SG1 ()
(setq ss (ssget "X" '((8 . "123"))))
)

i tried to create this code from internet but it is not working

0 Likes
Accepted solutions (1)
569 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant

How do you know it's not working?  You can determine whether it found anything with

(sslength ss)

which will tell you how many things it found.  Also, if it found things, it will report something like this when you use the command:

Command: SG1
<Selection set: 5d>

That would report nil if it didn't find anything.

 

All your code has been asked to do is put them in a selection set, which by itself will not "show" in any way in the drawing.  If you want them to then be selected/highlighted/gripped for you, that's another operation:

(sssetfirst nil ss)

Kent Cooper, AIA
0 Likes
Message 3 of 5

pendean
Community Legend
Community Legend

@karthikeyanskm Did you know...

 

pendean_0-1713964531791.png

 

0 Likes
Message 4 of 5

karthikeyanskm
Contributor
Contributor
Accepted solution

C:SG1 ( / sel1)
(setq sel1 (ssget "_X" '((8 . "123"))))
(sssetfirst nil sel1)
(princ)
)

 

this code works for me

0 Likes
Message 5 of 5

Kent1Cooper
Consultant
Consultant

Consider:

 

(defun C:SG1 (/ sel1)
  (if (setq sel1 (ssget "_X" '((8 . "123"))))
    (sssetfirst nil sel1); then

    (prompt "\nNo top-level object(s) found on Layer 123."); else

  ); if
  (princ)
)

 

Otherwise, if there's nothing on that Layer, your code will return:

(nil nil)

which could be confusing to Users.

Kent Cooper, AIA
0 Likes