Princ name of layer to command line

Princ name of layer to command line

Anonymous
Not applicable
314 Views
2 Replies
Message 1 of 3

Princ name of layer to command line

Anonymous
Not applicable

Please can someone help with an assoc & entget puzzle?

 

I'm having trouble making this lisp print the name of the layer selected printo to the command line.

 

It's supposed to display Layer 'mylayer' selected & at the end say x Items Deleted On Layer 'Mylayer'

 

This line is supposed to return the name of the layer:

 

(assoc 8 (entget ssl))

 

 

Code so far:

 

(defun c:dlayer ( / ssl ss2)
  (if (and (princ "\nSelect Layer to Delete ")
	   (setq ssl (ssget "_+.:E:S"))
	   (princ (strcat "\n Layer '" (assoc 8 (entget ssl)) "' Selected"))
	   (setq ss2 (ssget (list (assoc 8 (entget (ssname ssl 0)))))))
    (command "_.erase" ss2 "")
    )
  (if (= ss2 nil)
    (princ "\n No Items found")
    (princ (strcat "\n "(itoa (sslength ss2))" Items Deleted On Layer" (assoc 8 (entget ssl))))
    )
  (princ)
)

 

 

0 Likes
315 Views
2 Replies
Replies (2)
Message 2 of 3

ВeekeeCZ
Consultant
Consultant

Maybe something like this....

 

(defun c:dlayer ( / ssl ss2 lay)
  (if (and (princ "\nSelect Object to define Layer to Delete, ")
	   (setq ssl (ssget "_+.:E:S"))
	   (= 1 (sslength ssl))
	   (princ (strcat "\n Layer '" (setq lay (cdr (assoc 8 (entget (ssname ssl 0))))) "' Selected"))
	   (setq ss2 (ssget (list (cons 8 lay))))
	   )
    (progn
      (command "_.erase" ss2 "")
      (princ (strcat "\n "(itoa (sslength ss2))" Items Deleted On Layer '" lay "'.")))
    (princ " Nothing erased."))
  (princ)
)

 

;if you have selection set, then layer
(cdr (assoc 8 (entget (ssname (ssget) i)))) ; where i=0 as the first item of selectin set

;if you have entity selected using (entsel)
(cdr (assoc 8 (entget (car (entsel)))))
0 Likes
Message 3 of 3

Anonymous
Not applicable

Ahh I see now

 

I copied the code from a lisp that uses nentsel & I used a selection set.

 

It's clear now.

 

Thank you BeekeeCZ

0 Likes