Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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.

Posted (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 by Lee Mac
  • Like 2
  • Thanks 1
Posted

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

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

Posted

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

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

Posted

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.

  • 4 months later...
Posted

Hi Lee-Mac

 

That does not work with dynamic blocks.

Is thea a "easy" way to improve it?

 

Thank you

Posted

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?

Posted

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

Posted

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?

  • 10 months later...
Posted

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

  • 1 year later...
Posted

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

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

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

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

Hi Lee Mac,

 

Thank you !!! :D

 

This is exactly what I'm looking for.

 

regards

Bluebird

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