Jump to content

Exploding Blocks With Names Beginning "CU"


Recommended Posts

Posted

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. 

Posted

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

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

Posted

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

Posted (edited)
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
Posted

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?

 

Posted

updated code. fig vla-explode was like normal explode.

  • Thanks 1
Posted

Perfect, that works brilliantly. Thank you very much 🙂

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