Lisp to select the current layer

Lisp to select the current layer

jorgearone_inssitu
Enthusiast Enthusiast
830 Views
7 Replies
Message 1 of 8

Lisp to select the current layer

jorgearone_inssitu
Enthusiast
Enthusiast

hello everyone, i would like to make a lisp that can select all the elements of the current layer.
I have found the code to select a layer, but it has to pick an element. I would like to just select the current layer instantly.

This is code to select the elements of the desired Layer

(defun c:SALL ()

 (setq TargEnt (car (entsel "\nSelect object on layer to select: ")))

 (setq TargLayer (assoc 8 (entget TargEnt)))

 (sssetfirst nil (ssget "_X" (list TargLayer)))

 (princ "\n items selected")

)

 

This is the code to select that gives us the name of the current layer

(getvar "CLAYER")

 

What I don't know is how to put the two codes together.

0 Likes
Accepted solutions (2)
831 Views
7 Replies
Replies (7)
Message 2 of 8

Alexander.Rivilis
Mentor
Mentor
Accepted solution

Without testing:

(sssetfirst nil (ssget "_X" (list (cons 8 (getvar "CLAYER")))))

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 3 of 8

jorgearone_inssitu
Enthusiast
Enthusiast

Thank you very much Alexander.Rivilis, yes it works!

0 Likes
Message 4 of 8

jorgearone_inssitu
Enthusiast
Enthusiast

hello everyone
A query, I would like to add one more step to the lisp, but I have not been able to finish it, my knowledge in Lisp is very basic

I would like when the current layer is selected, the screen will focus especially on the selection, and the selection will stay.

I have tried, following the code that they provided me, but it remains selected (at least it is not seen with the classic selection boxes in each element)

 

(defun c:SR ()
(sssetfirst nil (ssget "_X" (list (cons 8 (getvar "CLAYER")))))
(command "zoom" "o")
(sssetfirst nil (ssget "_X" (list (cons 8 (getvar "CLAYER")))))
)

 

I just added the zoom command and replayed the current layer selection code.
But the elements are not (visually) selected

0 Likes
Message 5 of 8

Kent1Cooper
Consultant
Consultant

@jorgearone_inssitu wrote:

.... it is not seen with the classic selection boxes in each element ....


Maybe you have the GRIPOBJLIMIT System Variable set too low for the quantity of objects involved.

Kent Cooper, AIA
0 Likes
Message 6 of 8

jorgearone_inssitu
Enthusiast
Enthusiast

It's actually, I think,  a syntax problem.

jorgearone_inssitu_0-1690138480265.png

when executing the code

 

(sssetfirst nil (ssget "_X" (list (cons 8 (getvar "CLAYER")))))

 

select as seen (drawing is just an example)

 

jorgearone_inssitu_1-1690138629937.png

 

and adding the zoom for the selected objects, the model is restored for the selected zone (which are the elements of the current layer), the problem is that when executing the zoom command the selection is deleted

jorgearone_inssitu_2-1690138764034.png

 

and I would like the elements of the current layer to be reselected

 

jorgearone_inssitu_3-1690138827234.png

like this.

0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

If you're just going to immediately Zoom to the objects, I don't see any point in selecting/gripping/highlighting them twice, but I don't know why the second time doesn't happen.  If you're doing it the first time to become pre-selection for the Zoom, you could instead do the Zoom first with ordinary selection instead of pre-selection, and then do the selecting/gripping/highlighting.  Also, there's no need to re-select with the same filter code all spelled out again -- you can do it to the Previous selection:

(defun c:SR ()
  (command "_.zoom" "_object" (ssget "_X" (list (cons 8 (getvar 'clayer)))) "")
  (sssetfirst nil (ssget "_P"))
)

 

Kent Cooper, AIA
0 Likes
Message 8 of 8

jorgearone_inssitu
Enthusiast
Enthusiast

yes it works, thank you very much.
My level in Lisp doesn't even reach basic, from what I see. Again thank you very much.

0 Likes