Jump to content

Explode nested blocks only


Cazza

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Lee Mac
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 4 months later...

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • 10 months later...

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

Link to comment
Share on other sites

  • 1 year later...

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

Link to comment
Share on other sites

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)

  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

  • Like 2
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...