Jump to content

Lisp Request - Select object in paperspace in across multiple layouts


Recommended Posts

eyeofnewt555

If only QSelect weren't lying when it gives the option to search "Entire Drawing."

 

As the title says, I'd like to be able to grab all instances of an object (typically a block) across multiple layout tabs in paper space (if it were in model, this wouldn't be a problem). The end goal being to change a property across the board. I know there's GATTE if it's a block attribute that needs changing, but that's not always the case.

 

Ideally, some way to grab all instances with optional filters would be great. Really, I just want QSelect to have better functionality.

 

It looks like someone addressed it here, but I'm not having any success with that method.

 

Thanks for any help!

Link to post
Share on other sites
eyeofnewt555

The name will change. I'm not looking for a one time option. I guess prompting to select an instance of the block or type a name would be great.

 

Mostly the blocks will be static, but could occasionally be dynamic, in which case it would be helpful to be able to filter the selection based on which state the block is in.

Link to post
Share on other sites

This should grip all blocks in the drawing, with the same name:

 

(defun C:test ( / blk SS nSS i e )
 (setvar 'errno 0)
 (while (/= 52 (getvar 'errno))
   (setq blk (car (entsel "\nSelect block to filter <exit>: ")))
   (cond 
     ((= 7 (getvar 'errno)) (princ) (setvar 'errno 0))
     ((and blk (/= "INSERT" (cdr (assoc 0 (entget blk))))) (princ))
     (blk 
       (setq blk (vla-get-EffectiveName (vlax-ename->vla-object blk)))
       (setq SS (ssget "_X" (list (cons 0 "INSERT"))))
       (setq nSS (ssadd))
       (repeat (setq i (sslength SS))
         (setq e (ssname SS (setq i (1- i))))
         (and (eq blk (vla-get-EffectiveName (vlax-ename->vla-object e)))
           (ssadd e nSS)
         )
       )
       (sssetfirst nil nSS)
       (setvar 'errno 52)
     )
   )
 )
 (princ)
)

Link to post
Share on other sites
eyeofnewt555

Any number of things. Delete them all (I know there are other ways to do this too), change their layer (or any other property/attribute), maybe even move them all using displacement (lets say you've got a scale bar on multiple layouts that now needs to be an inch to the left on every sheet).

 

I know there are generally work arounds for most of these, but it'd be handy to have one command to do it all.

Link to post
Share on other sites
eyeofnewt555

Perfect! It looks like it kicks out everything that's not on the current layout if you try to run a command on the selection set. But changing anything in the properties panel works like a charm--which is pretty much all I need.

 

Thanks a ton, Grrr!

Link to post
Share on other sites
Perfect! It looks like it kicks out everything that's not on the current layout if you try to run a command on the selection set. But changing anything in the properties panel works like a charm--which is pretty much all I need.

 

I didn't knew about that, but the code is supposed to grip every occurence in all layouts. BTW that suggestion you addressed should work for non-dynamic blocks.

 

Thanks a ton, Grrr!

You're welcome!

Link to post
Share on other sites

I do some stuff like this but in a different way just atke advantage of Setvar CTAB which can open every layout 1 at a time and do something also adding the 410 filter.

(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for lay (vla-get-Layouts doc)
(setq plotabs (cons (vla-get-name lay) plotabs))
)
(foreach tabname plotabs 
     ; no need to regen each sheet
     (setq ss1 (ssget "x"  (list (cons 0 "INSERT") (cons 2 bname)(cons 410 tabname))))
and so on do your move etc as a defun at this point

Link to post
Share on other sites
  • 1 month later...
This should grip all blocks in the drawing, with the same name:

 

(defun C:test ( / blk SS nSS i e )
 (setvar 'errno 0)
 (while (/= 52 (getvar 'errno))
   (setq blk (car (entsel "\nSelect block to filter <exit>: ")))
   (cond 
     ((= 7 (getvar 'errno)) (princ) (setvar 'errno 0))
     ((and blk (/= "INSERT" (cdr (assoc 0 (entget blk))))) (princ))
     (blk 
       (setq blk (vla-get-EffectiveName (vlax-ename->vla-object blk)))
       (setq SS (ssget "_X" (list (cons 0 "INSERT"))))
       (setq nSS (ssadd))
       (repeat (setq i (sslength SS))
         (setq e (ssname SS (setq i (1- i))))
         (and (eq blk (vla-get-EffectiveName (vlax-ename->vla-object e)))
           (ssadd e nSS)
         )
       )
       (sssetfirst nil nSS)
       (setvar 'errno 52)
     )
   )
 )
 (princ)
)

 

 

Hello. This looks to be exactly what I need. I created a lisp of the above code and used APPLOAD to load it. I am now unsure how to initiate the command. Any help would be appreciated. This could save me a lot of time. I need to change the layer of a block in 20 different layout tabs across 15 different sheet sets. Thanks!

Link to post
Share on other sites

Something like this

 

(defun AH:uptitle ( / doc lay plotabs newlay bname ss1)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for lay (vla-get-Layouts doc)
(setq plotabs (cons (vla-get-name lay) plotabs))
) ; for
(setq bname (vla-get-name (vlax-ename->vla-object (car (entsel "\nPick block")))))
(setq newlay (getstring "Enter layer name"))
(foreach tabname plotabs 
(if (/= "Model" tabname)
(setq ss1 (ssget "x"  (list (cons 0 "INSERT") (cons 2 bname)(cons 410 tabname))))
) ; if
(repeat (setq x (sslength ss1))
(vla-put-layer (vlax-ename->vla-object (ssname SS1 (setq x (- x 1)))) newlay)
) ; repeat
(setq ss1 nil)
) ; for
) ; defun
(AH:uptitle)

Link to post
Share on other sites
  • 2 years later...
gonecrawfishin

Hi all, Does anyone have a similar LISP that works for all types of objects, not just blocks? I'm looking to do some purging, and want to select everything on a particular layer across all paperspaces. Thanks!

 

Link to post
Share on other sites
5 hours ago, gonecrawfishin said:

Hi all, Does anyone have a similar LISP that works for all types of objects, not just blocks? I'm looking to do some purging, and want to select everything on a particular layer across all paperspaces. Thanks!

 

 

Try

 

(setq ss (ssget "_X"  (list (cons 8 layernames))));; eg layernames = "0,DEFPOINTS,....."

 

Link to post
Share on other sites
gonecrawfishin

Thanks dlanorh. I tried that, but then the command line returns <Selection set: 23> , but I don't actually have any objects selected. 

 

Next, I tried DELETE in teh command line, and then I pasted that script above. Command line said

<selection set: 2f>

16 found

16 were not in current space

 

I'm not really sure what it's doing, or why it's returning 23 in one case, 16 in another. Thoughts?

Link to post
Share on other sites
3 hours ago, gonecrawfishin said:

Thanks dlanorh. I tried that, but then the command line returns <Selection set: 23> , but I don't actually have any objects selected. 

 

Next, I tried DELETE in teh command line, and then I pasted that script above. Command line said

<selection set: 2f>

16 found

16 were not in current space

 

I'm not really sure what it's doing, or why it's returning 23 in one case, 16 in another. Thoughts?

 

The highlighted item is the name of the selection sets

 

Try this

 

 (defun c:test (/ ss)
   (setq ss (ssget "_X" '((0 . "0,DEFPOINTS")))) ;; This should select every item on layers "defpoints" and "0". Items will not be highlighted 
   (if ss                                        ;;TEST if anything selected 	
      (princ (sslength ss))                      ;; If YES This will tell you how many items are in the selection set
      (princ "Selection set empty")
   );end_if
   (princ)
 );end_defun

 

Link to post
Share on other sites
4 hours ago, gonecrawfishin said:

Thanks dlanorh. I tried that, but then the command line returns <Selection set: 23> , but I don't actually have any objects selected. 

 

Next, I tried DELETE in teh command line, and then I pasted that script above. Command line said

<selection set: 2f>

16 found

16 were not in current space

 

I'm not really sure what it's doing, or why it's returning 23 in one case, 16 in another. Thoughts?

If you want to delete items on all layouts, try something like this:

(defun c:foo (/ s)
  (if (setq s (ssget "_X" '((8 . "0,DEFPOINTS"))));; Items on layer 0 and defpoints
    (foreach o (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex s)))
      (vl-catch-all-apply 'vla-delete (list o))
    )
  )
  (princ)
)(vl-load-com)

Note that @dlanorh latest ssget filter will always return nothing since he's using code 0 rather than 8 for layers.

Edited by ronjonp
  • Like 1
Link to post
Share on other sites
11 minutes ago, ronjonp said:

If you want to delete items on all layouts, try something like this:


(defun c:foo (/ s)
  (if (setq s (ssget "_X" '((8 . "0,DEFPOINTS"))));; Items on layer 0 and defpoints
    (foreach o (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex s)))
      (vl-catch-all-apply 'vla-delete (list o))
    )
  )
  (princ)
)(vl-load-com)

Note that @dlanorh latest ssget filter will always return nothing since he's using code 0 rather than 8 for layers.

 

:facepalm: Doh!

Link to post
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
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...