Damian120 Posted November 10, 2021 Posted November 10, 2021 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. Quote
mhupp Posted November 10, 2021 Posted November 10, 2021 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) ) Quote
Jonathan Handojo Posted November 10, 2021 Posted November 10, 2021 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: Is dynamic AND: 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. Quote
elyosua Posted November 10, 2021 Posted November 10, 2021 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. Quote
Damian120 Posted November 11, 2021 Author Posted November 11, 2021 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 Quote
mhupp Posted November 11, 2021 Posted November 11, 2021 (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 November 11, 2021 by mhupp prompt 1 Quote
Damian120 Posted November 11, 2021 Author Posted November 11, 2021 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? Quote
mhupp Posted November 11, 2021 Posted November 11, 2021 updated code. fig vla-explode was like normal explode. 1 Quote
Damian120 Posted November 11, 2021 Author Posted November 11, 2021 Perfect, that works brilliantly. Thank you very much Quote
Recommended Posts
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.