Jump to content

Exploding Blocks With Names Beginning "CU"


Damian120

Recommended Posts

I am new to AutoCAD Lisp and I am not quite sure how to do what I need to do. I need a piece of coding that explodes all blocks in a drawing who's name starts with letters "CU". Any help on this would be greatly appreciated. 

Link to comment
Share on other sites

Nothing fancy will explode any block in model space starting with CU or cu.

 

(defun C:BLKEXP (/ ss)
  (if (setq SS (ssget "_X" '((0 . "INSERT")(2 . "CU*")(410 . "Model"))))  ;CU* is wildcard for any name that starts with CU
    (vl-cmdf "_.Explode" SS "")
  )
  (prompt "\nAll CU block Exploded")
  (princ)
)
Link to comment
Share on other sites

7 minutes ago, mhupp said:

Nothing fancy will explode any block in model space starting with CU or cu.

 


(defun C:BLKEXP (/ ss)
  (if (setq SS (ssget "_X" '((0 . "INSERT")(2 . "CU*")(410 . "Model"))))  ;CU* is wildcard for any name that starts with CU
    (vl-cmdf "_.Explode" SS "")
  )
  (prompt "\nAll CU block Exploded")
  (princ)
)

 

So far to my knowledge, that would only work if the block isn't user-defined. For me, that would be when the block:

 

  1. Is dynamic AND:
  2. In a state in which the dynamic properties of the block have been modified (not in a state of reset).

Ssget doesn't seem to be compatible with user-defined blocks (modified dynamic blocks seem to give the block another name). The only way I know to get around it is to iterate through the selection set and use ActiveX to take the effective name of the block. At least for me that's how I've been dealing with block names.

Link to comment
Share on other sites

4 hours ago, Damian120 said:

I am new to AutoCAD Lisp and I am not quite sure how to do what I need to do. I need a piece of coding that explodes all blocks in a drawing who's name starts with letters "CU". Any help on this would be greatly appreciated. 

 

You can use qselect command for it.

Link to comment
Share on other sites

Thank you for your fast answer, the code almost does what I require. It explodes only one block at a time. Is there a way of getting it to do all of the CU blocks on the drawing in one run? If this is possible it would be fantastic.

 

Thank you in advance

Link to comment
Share on other sites

9 hours ago, Damian120 said:

It explodes only one block at a time.

 

The first code should be exploding them all at once at least it did on my test.

This new code will walk thought all blocks in the drawing one at a time and explode them if they start with CU.

 

(defun C:BLKEXP-CU (/ layouts layout blk)
  (vl-load-com)
  (setq layouts (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))))
  (vlax-for layout layouts
    (vlax-for blk (vla-get-block layout)
      (if (and (= "AcDbBlockReference" (vla-get-objectname blk)) (wcmatch (strcase (vla-get-name blk)) "CU*"))
        (progn
          (vl-catch-all-error-p (vl-catch-all-apply 'vla-explode (list blk)))
          (vl-catch-all-error-p (vl-catch-all-apply 'vla-delete (list blk)))
        )
      )
    )
  )
  (prompt "\nAll CU block Exploded")
  (princ)
)

 

 

Edited by mhupp
prompt
  • Thanks 1
Link to comment
Share on other sites

Thankyou mhupp, it does now explode all the blocks however, it also makes a copy of the block. i.e. you end up with an exploded version of the block plus the original block under it. Do you have any idea why this is happening?

 

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