Jump to content

Select all objects that are on same layer as entity selection


Recommended Posts

Posted

Hey everybody, I need some help.

 

I'm trying to make a simple that will add all objects on a layer specified by an entity selection to the current selection set, that way I can manipulate them all as needed.

 

What I've got so far is:

 

(defun c:qs ()
(setq obj (entsel "\nSelect object on desired layer: "))
(while (not obj) (setq obj (entsel "\nNo object selected, try again: ")))
(setq ent (entget (car obj))
lay (cdr (assoc 8 ent)))
(ssget "_X" '((8 . lay)))
(princ (strcat "\nEverything on layer " lay " selected."))
(princ))

 

But I keep getting errors no matter how much I tweek it.

 

Any help would be greatly appriciated.

Posted

So I got it one step closer with:

 

(defun c:qs (/ obj ent lay)
 (setq obj (entsel "\nSelect object on desired layer: "))
 (while (not obj) (setq obj (entsel "\nNo object selected, try again: ")))
 (setq ent (entget (car obj))
lay (cdr (assoc 8 ent)))
 (ssget "_X" (list (cons 8 lay)))
 (princ (strcat "\nEverything on layer " lay " selected."))
 (princ))

 

But it doesn't add everything to the current selection set, like when the grips show up.

 

Any ideas?

Posted

Nevermind, found this:

 

http://www.cadtutor.net/forum/showthread.php?t=30154

 

And came up with this:

 

(defun c:qs (/ obj ent lay)
(setq obj (entsel "\nSelect object on desired layer: "))
(while (not obj) (setq obj (entsel "\nNo object selected, try again: ")))
(setq lay (cdr (assoc 8 (entget (car obj)))))
(sssetfirst nil (ssget "_X" (list (cons 8 lay))))
(princ (strcat "\nEverything on layer " lay " selected."))
(princ))

Posted

Nice one, you could shorten it to this if you wanted :)

 

(defun c:qs ( / e )

 (while (not (setq e (car (entsel))))
   (princ "\n** Come on, you gotta do better than that **"))

 (sssetfirst nil (ssget "_X" (list (assoc 8 (entget e)))))

 (princ))

Posted

Very cool guys, thanks.

  • 1 month later...
Posted

Any idea how I could change this so that if I already have entities selected that it will add everything on the layer of the picked object to the selection set? That way I could run this more than once and select everthing on multiple layers.

Posted

Why not...

 

(defun c:SA (/ pf ent ss)
 ;; Alan J. Thompson, 06.17.10
 (setq pf (ssget "_I"))
 (if (and (setq ent (car (entsel "\nSelect on layer: ")))
          (setq ss (ssget "_X"
                          (list (assoc 8 (entget ent))
                                (if (eq 2 (getvar "cvport"))
                                  (cons 410 "Model")
                                  (cons 410 (getvar "ctab"))
                                )
                          )
                   )
          )
     )
   ((lambda (i)
      (if (eq (type pf) 'PICKSET)
        (while (setq e (ssname pf (setq i (1+ i))))
          (ssadd e ss)
        )
      )
      (sssetfirst nil ss)
    )
     -1
   )
 )
 (princ)
)

Posted

works like a charm, thanks a ton

Posted
works like a charm, thanks a ton

You're welcome.

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...