Multiple layers select Lisp

Multiple layers select Lisp

k005
Advisor Advisor
3,193 Views
7 Replies
Message 1 of 8

Multiple layers select Lisp

k005
Advisor
Advisor

Hello friends

 

How can I make multiple selections and select all objects in the relevant layer?

0 Likes
Accepted solutions (1)
3,194 Views
7 Replies
Replies (7)
Message 2 of 8

pbejse
Mentor
Mentor

@k005 wrote:

Hello friends

 

How can I make multiple selections and select all objects in the relevant layer?


 

What do you mean multiple? multiple objects of the same type or one just one type of object?

This line will prompt the user to select "LWPOLYLINE" with "Drainpipe" layer  on screen

 

(setq ss (ssget '((0 . "LWPOLYLINE")(8 . "Drainpipe"))))

 

This will select all "LWPOLYLINE" with "Drainpipe" layer on "Model" space without user prompt

 

(setq ss (ssget "_X" '((0 . "LWPOLYLINE")(8 . "Drainpipe")(410 . "Model"))))

 

This will select all "LWPOLYLINE" and/or "INSERT" (blocks)  with "Drainpipe" layer on "Model" space without user prompt

 

(setq ss (ssget "_X" '((0 . "LWPOLYLINE,INSERT")(8 . "Drainpipe")(410 . "Model"))))

 

 HTH

 

0 Likes
Message 3 of 8

Kent1Cooper
Consultant
Consultant

If you want to select objects of any type, and find all objects of any type on the Layers of those selected objects, try using LAYISO.  It will turn off all the Layers other than those of the selected objects, and you should then be able to just select everything visible.  LAYUNISO turns those other Layers back on.

 

This will be complicated by the possibility of objects on such Layers that are nested in Blocks inserted on other Layers, but I expect that will be a complication of any approach.

Kent Cooper, AIA
0 Likes
Message 4 of 8

k005
Advisor
Advisor

@pbejse 

 

First of all, sorry for my late reply...

 

Now let me explain: The lisp code at the bottom only selects the X layer and ends.

 

What I want to do is select All objects belonging to both X, Y and N layers.

 

X Y N --» given as the symbolic layer name.

 

(defun C:SEL ( / e lay ss)
 (setq e (nentsel "Select entity on a layer: "))
 (if e (setq ss (ssget "_X" (list(cons 8 (cdr (assoc 8 (entget (car e)))))))))
 (if (zerop (getvar"CMDACTIVE"))
  (progn (sssetfirst ss ss)(princ"Use 'P' for this selection set: "))
 )
 ss
)

 

0 Likes
Message 5 of 8

k005
Advisor
Advisor

@Kent1Cooper 

 

It would be much more useful if we could do it via Lisp.

0 Likes
Message 6 of 8

pbejse
Mentor
Mentor
Accepted solution

@k005 wrote:

First of all, sorry for my late reply...

Now let me explain: The lisp code at the bottom only selects the X layer and ends.

What I want to do is select All objects belonging to both X, Y and N layers.

X Y N --» given as the symbolic layer name.


 

The program enables the user to select an object

 

(setq e (nentsel "Select entity on a layer: "))

 

and then proceeds to retrieve the layer of the selected entity

 

(cons 8 (cdr (assoc 8 (entget (car e)))))

 

and use the value of the layer as a filter for ssget

(setq ss (ssget "_X"
		    (list (cons 8 (cdr (assoc 8 (entget (car e))))))
	     )
    )

Naturally, an object can only have one layer. 

 

Now , what we an do is to modify the code to prompt the user to continue selecting an entity in a loop, build a list of layer names, and use that for the filter.

(defun C:SEL (/ e lay ss lname layerlist)
  (While
    (setq e (nentsel "\nSelect entity on a layer: "))
    (princ (strcat "\nSelected entity layer name "
		   (setq lname (cdr (assoc 8 (entget (car e)))))
	   )
    )
    (setq layerlist (cons lname layerlist))
    (redraw (car e) 3)
    )
  (setq ss (ssget "_X" (list (cons 8
			 (apply 'strcat (mapcar '(lambda (n)
						   (strcat n ",")) layerlist)
			      )
		     )
	    )
	  )
	)
  (if (zerop (getvar "CMDACTIVE"))
    (progn (sssetfirst ss ss)
	   (princ "Use 'P' for this selection set: ")
    )
  )
  ss
)

HTH

 

Message 7 of 8

k005
Advisor
Advisor

@pbejse 

 

Thank you very much. It's ok. 🤗

0 Likes
Message 8 of 8

mkmkameniar
Explorer
Explorer

Hi @pbejse, your lisp works perfectly. However, would it be possible to change it to work with blocks too? I mean, when I run the lisp and click on the block in a particular layer, it wouldn't choose objects from this layer, but from layer of the nested object in block (which is in my case 0).

0 Likes