Dear Forum,
While trying to find out how to select all blocks and explode them until there are no more blocks (but not 3D surfaces), I found this post:
At the end of the thread CADDapult writes out some code that seems to do what I want. Question is... how to do enter/use this code. I have not used code in autocad before (have done a small bit in excel).
Any insight woudl be appreciated.
Solved! Go to Solution.
Solved by hgasty1001. Go to Solution.
Hi,
As is saturday, it seems you are in a hurry, try this little code to explode all the explodable blocks in the drawing
(defun c:blkxplode(/ ss) (setq ss (ssget "x" '((0 . "INSERT")))) (if ss (progn (setvar "qaflags" 1) (command "._explode" ss "") (setvar "qaflags" 0) ) (alert "No Blocks selected") ) )
In order to load lisp files, you have to issue the Appload command at the command line or in the Tools Menu, Load Application, and then in the command line again, type the command BlkXplode. In order to use other lisp files, you have to inspect the file for functions with the pattern: (defun C:SomeNameHere()...) They are Autolisp defined commands.
Gaston Nunez
Thank you very much Gaston!! Does the trick. Was worth giving up the saturday after all!!!
So I pasted that into notepad, saved with a .lsp file name and loaded up as you mentioned. So is that the norm?
@hgasty1001 wrote:
.... try this little code to explode all the explodable blocks in the drawing
....
If there are any nested Blocks as ingredients in the definitions of other Blocks, and you want all of those also Exploded, you would want to run that several times. Or you could alter it to run itself as many times as it continues to find Blocks. In simplest terms:
(defun c:blkxplodestack (/ ss)
(setvar "qaflags" 1)
(while
(setq ss (ssget "x" '((0 . "INSERT"))))
(command "._explode" ss "")
); while
(setvar "qaflags" 0)
)
However, that [and gasty's original] would also find Xrefs [and, if you ever use them, Windows Metafiles] that can't be Exploded. So really, it ought to run through each item in a selection set, and only if it's an Explodable kind of Insert object, Explode it. [Also, doing it that way (Exploding only one at a time), no messing with the QAFLAGS System Variable is necessary.] There should also be some kind of marker so it will know once it has encountered a selection set that contains no ordinary Blocks among the Insert objects it found, and stop checking -- otherwise it would get into an endless loop. I would bet that there's something out there already that will do something like that, but if you don't find it, it wouldn't be hard to work out.
The following program will recursively explode all primary & nested block references (nested to any depth) excluding xrefs, in all drawing layouts (the EXPLODE command will ignore objects in inactive drawing layouts):
;; Explode All Blocks - Lee Mac ;; Recursively explodes all primary & nested blocks (nested to any depth) in all drawing layouts. (defun c:eab ( ) (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (if (= :vlax-false (vla-get-isxref blk)) (vlax-for obj blk (explodeblock obj)) ) ) (princ) ) (defun explodeblock ( obj / lst ) (if (and (= "AcDbBlockReference" (vla-get-objectname obj)) (vlax-method-applicable-p obj 'explode) (vlax-write-enabled-p obj) ) (if (not (vl-catch-all-error-p (setq lst (vl-catch-all-apply 'vlax-invoke (list obj 'explode)) ) ) ) (progn (vla-delete obj) (foreach obj lst (explodeblock obj)) ) ) ) ) (vl-load-com) (princ)
Note that the above will ignore objects on locked layers.
Lee
Thank you all for your replies. This will make the upcoming week some what manageable
Gaston's initial response did what I initally needed (although as Kent mentioned, does need to be rerun for nested blocks). I therefore marked it as the solution. However, Lee's solution is super sweet as it takes the repeat running out of it.
Again, thanks to all!
You're most welcome dshannon - I'm glad it helps!