Cazza Posted September 4, 2012 Posted September 4, 2012 Hi all, Is there a way to explode nested blocks within a block without exploding the original block that is shown in my drawing? Any help would be greatly appreciated. Quote
MSasu Posted September 4, 2012 Posted September 4, 2012 If is about only one block, then call BEDIT command and next use QSELECT or FILTER to find all nested blocks and explode them. Save the changes to said block definition. Quote
Cazza Posted September 4, 2012 Author Posted September 4, 2012 Thanks for the reply MSasu, Unfortunately there are many different blocks, most of them only occur once or twice within my drawing. I was hoping to select all the blocks and explode all of the nested blocks so that they retain their block definition but only on one level rather than the several levels that they are currently on. Quote
Lee Mac Posted September 4, 2012 Posted September 4, 2012 (edited) Try something like this: (defun c:exnest ( ) (vlax-for blk (vla-get-blocks (LM:acdoc)) (if (and (= :vlax-false (vla-get-isxref blk)) (= :vlax-false (vla-get-islayout blk)) ) (vlax-for obj blk (if (and (= "AcDbBlockReference" (vla-get-objectname obj)) (null (vl-catch-all-error-p (vl-catch-all-apply 'vla-explode (list obj)))) ) (vl-catch-all-apply 'vla-delete (list obj)) ) ) ) ) (command "_.-purge" "_B" "*" "_N") (vla-regen (LM:acdoc) acallviewports) (princ) ) ;; Active Document - Lee Mac ;; Returns the VLA Active Document Object (defun LM:acdoc nil (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object)))) (LM:acdoc) ) Edited September 4, 2012 by Lee Mac 2 1 Quote
Tharwat Posted September 4, 2012 Posted September 4, 2012 I have written almost the same code but the problem is that the nested blocks would be exploded but a copy of the same block would be kept inside . Could any of the Sys. vars take affects on this ? Thanks Quote
Lee Mac Posted September 4, 2012 Posted September 4, 2012 I have written almost the same code but the problem is that the nested blocks would be exploded but a copy of the same block would be kept inside . Good point Tharwat, I had overlooked the fact that the Explode method creates an exploded copy of the object - I have now updated my code above and have also included a block purge. Quote
Cazza Posted September 5, 2012 Author Posted September 5, 2012 Hi Lee Mac, Thanks for the reply. I tried to use your code above but I got the response "No unreferenced blocks found." and when I enter the block editor to see if it has removed the nested block the nested block is still there. Is this code trying to purge out unreferenced blocks? I was looking for something that would allow you to select the blocks (with a window), that would then enter the block editor and explode everything but have the original block remain as a block. At the moment I have to enter the block editor for each block and explode the nested blocks myself but this is very time consuming as there are so many different types of blocks (with nested blocks inside of them). Quote
Lee Mac Posted September 5, 2012 Posted September 5, 2012 I tried to use your code above but I got the response "No unreferenced blocks found." and when I enter the block editor to see if it has removed the nested block the nested block is still there. Is this code trying to purge out unreferenced blocks? My program will iterate over all block definitions within the block collection, and, if a block definition contains a nested block, the nested block is exploded. Finally, the program will purge the block collection to remove any unreferenced block definitions. The code seems to work fine in my tests, even with blocks for which the 'Allow exploding' option is unticked. Are you able to attach an example drawing? Quote
Cazza Posted September 5, 2012 Author Posted September 5, 2012 Hi Lee Mac, I had another go using your code and it works great, I must have been doing something wrong the first time round. Thank you again for your posts. Quote
Lee Mac Posted September 6, 2012 Posted September 6, 2012 You're very welcome Cazza, happy to help Quote
msarqui Posted January 25, 2013 Posted January 25, 2013 Hi Lee-Mac That does not work with dynamic blocks. Is thea a "easy" way to improve it? Thank you Quote
Lee Mac Posted January 25, 2013 Posted January 25, 2013 I see no reason why the program should not work on dynamic blocks, and after a quick test, the nested blocks within my dynamic block references have been exploded - what issues are you experiencing? Quote
msarqui Posted January 25, 2013 Posted January 25, 2013 I attached my block so I hope you can see what hapens. Here in my AutoCAD, the result is weird... It puts all visibilitys together Thanks for the reply! To Lee-Mac.dwg Quote
msarqui Posted January 28, 2013 Posted January 28, 2013 I just realized that this problem does not happen with your command iBurst. The problem is that iBurst changes the draw order and need to select the blocks as many times as the are nested. Is it possible to keep the draw order and explode all nested in one shot until does not have anymore? Quote
JanHarink Posted December 4, 2013 Posted December 4, 2013 Is it possible to purge or explode nested blocks by selection. The projsymbolstyle.dwg contains all project symbols, but also a lot of symbols which will not be used in AutoCAD P&ID. All the unused symbols are nested in another block, but i can not figure out where they are nested. I have tried the exnest.lsp from LeeMac, but this doesn't seem to work. regards, Jan Quote
Bluebird1973 Posted July 7, 2015 Posted July 7, 2015 Hi, I know, it is an old thread, but is it possible to do a modification for single selection at Lee's code? If I could, I would it do by myself. regards Bluebird Quote
Tharwat Posted July 7, 2015 Posted July 7, 2015 Hi, I know, it is an old thread, but is it possible to do a modification for single selection at Lee's code? Try this code. (defun c:Test (/ s doc) (princ "\nPick on single block to explode blocks within") (if (setq s (ssget "_+.:S:L:E" '((0 . "INSERT")))) (progn (vlax-for obj (vla-item (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object) ) ) ) (vla-get-effectivename (vlax-ename->vla-object (ssname s 0)) ) ) (if (and (= "AcDbBlockReference" (vla-get-objectname obj)) (null (vl-catch-all-error-p (vl-catch-all-apply 'vla-explode (list obj)) ) ) ) (vl-catch-all-apply 'vla-delete (list obj)) ) ) ) ) (command "_.-purge" "_B" "*" "_N") (vla-regen doc acallviewports) (princ) )(vl-load-com) 1 Quote
Bluebird1973 Posted July 7, 2015 Posted July 7, 2015 Hi Tharwart, Thank you ! ... but it works not deep enough ... I have up to 5 nested blocks into each other. Is it possible to get all nested blocks? regards Bluebird Quote
Lee Mac Posted July 7, 2015 Posted July 7, 2015 ... but it works not deep enough ...I have up to 5 nested blocks into each other. Is it possible to get all nested blocks? Please try the following: (defun c:exnest ( / doc ent ) (while (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect block: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (null ent) nil) ( (/= "INSERT" (cdr (assoc 0 (entget ent)))) (princ "\nSelected object is not a block.") ) ) ) ) (if ent (progn (vlax-for obj (vla-item (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object)))) (LM:name->effectivename (cdr (assoc 2 (entget ent)))) ) (exnest:explode obj) ) (vla-regen doc acallviewports) ) ) (princ) ) (defun exnest:explode ( obj / lst ) (if (and (= "AcDbBlockReference" (vla-get-objectname obj)) (vlax-write-enabled-p obj) (not (vl-catch-all-error-p (setq lst (vl-catch-all-apply 'vlax-invoke (list obj 'explode))))) ) (progn (foreach obj lst (exnest:explode obj)) (vla-delete obj) ) ) ) ;; Block Name -> Effective Block Name - Lee Mac ;; blk - [str] Block name (defun LM:name->effectivename ( blk / rep ) (if (and (wcmatch blk "`**") (setq rep (cdadr (assoc -3 (entget (cdr (assoc 330 (entget (tblobjname "block" blk)))) '("AcDbBlockRepBTag") ) ) ) ) (setq rep (handent (cdr (assoc 1005 rep)))) ) (cdr (assoc 2 (entget rep))) blk ) ) (vl-load-com) (princ) 2 Quote
Bluebird1973 Posted July 7, 2015 Posted July 7, 2015 Hi Lee Mac, Thank you !!! This is exactly what I'm looking for. regards Bluebird 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.