Jump to content

Lisp to select all objects on specified layers


PianoMan

Recommended Posts

Hi all! I'm trying to create a lisp that, when activated, will automatically select and delete all objects on several layers, ideally that are written into the lisp itself so I don't have to enter anything. Unfortunately, while I can make sense of code with time, I have a very limited understanding of what's out there, and don't know what commands I need to do what I want to do.

 

I got a decent start with this code:

(defun c:SALL ()
(setq TargetEnt (car (entsel "\nSelect object on layer to select: ")))
(setq TargetLayer (assoc 8 (entget TargetEnt)))
(sssetfirst nil (ssget "_X" (list TargetLayer)))
(princ)
)

 

taken from

here, but I can't figure out how to have it automatically select items from specified layers, and adding an erase command at the end of the whole thing doesn't seem to work.

 

If anyone could help me finish this, I would greatly appreciate it!

Link to comment
Share on other sites

Welcome to CADTutor.

 

Here is a very simple form of such a program:

(defun c:delonlayer ( / i s )
   (if (setq s (ssget "_X" '((8 . "[highlight]Layer1,Layer2,Layer3[/highlight]"))))
       (repeat (setq i (sslength s)) (entdel (ssname s (setq i (1- i)))))
   )
   (princ)
)

Link to comment
Share on other sites

Maybe a command line version ?

 

(defun delonlayer (lays / i s )
   (if (setq s (ssget "_X" (List (cons 8 lays))))
       (repeat (setq i (sslength s)) (entdel (ssname s (setq i (1- i)))))
   )
   (princ)
)

type this on command line
(delonlayer ""Layer1,Layer2,Layer3")

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...