Jump to content

Xplode All Blocks


ggarcia

Recommended Posts

Hello

I'm new to this forum and was hoping that someone could help with the lisp file I'm working on.

 

I have a lisp file that deletes all blocks within a drawing and works with one exception. If a block is unexplode able it just hangs. How can I test for this and just have the routine proceed to the next block??

 

here is the code I currently have.....

 

(defun gg_xBlocks ()
 (setvar "qaflags" 1)
(setq gg_allblks (ssget "X" (list (cons 0 "INSERT"))))
(while (/= gg_allblks nil) 
 (progn
  (command "_.explode"  gg_allblks "")
  (setq gg_allblks (ssget "X" (list (cons 0 "INSERT"))))
 );progn
);while
(setvar "qaflags" 0)
(princ)
)

Thanks for the help in advance.

 

g

Edited by SLW210
Link to comment
Share on other sites

Welcome to CADTutor GGarcia, hope you like it here :)

 

Here's a quick tip about code formatting:

http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines

Link to comment
Share on other sites

Here's one way, as a quick sub:

 

(defun _isExplodable ( name ) (vl-load-com)
 ;; © Lee Mac 2010
 (if
   (not
     (vl-catch-all-error-p
       (setq BlockDefinition
         (vl-catch-all-apply (function vla-item)
           (list
             (vla-get-Blocks
               (vla-get-ActiveDocument
                 (vlax-get-acad-object)
               )
             )
             name
           )
         )
       )
     )
   )
   (or
     (not (vlax-property-available-p BlockDefinition 'Explodable))
     (eq :vlax-true (vla-get-Explodable BlockDefinition))
   )
 )
)

Call with Block Name:

 

(_isExplodable "BlockName")

Returns T or nil.

 

You could also modify the 'Explodable' property of the block definition to make the block explodable :)

Link to comment
Share on other sites

This is how I might approach the problem:

 

(defun c:ExplodeAllBlocks ( / *error* _StartUndo _EndUndo doc locked ss )
 (vl-load-com)
 ;; © Lee Mac 2010

 ;; Error Handler

 (defun *error* ( msg )
   (if locked
     (mapcar
       (function
         (lambda ( l )
           (vl-catch-all-apply 'vla-put-lock (list l :vlax-true))
         )
       )
       locked
     )
   )
   (if doc (_EndUndo doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (defun _StartUndo ( doc ) (_EndUndo doc)
   (vla-StartUndoMark doc)
 )

 (defun _EndUndo ( doc )
   (if (= 8 (logand 8 (getvar 'UNDOCTL)))
     (vla-EndUndoMark doc)
   )
 )

 ;; Start an Undo Mark

 (_StartUndo
   (setq doc
     (vla-get-ActiveDocument
       (vlax-get-acad-object)
     )
   )
 )

 ;; Set all blocks to be explodable

 (vlax-map-collection (vla-get-Blocks doc)
   (function
     (lambda ( blockdefinition )
       (if (vlax-property-available-p blockdefinition 'explodable)
         (vla-put-explodable blockdefinition :vlax-true)
       )
     )
   )
 )

 ;; Unlock all Layers

 (vlax-for l (vla-get-layers doc)
   (if (eq :vlax-true (vla-get-lock l))
     (progn
       (vla-put-lock l :vlax-false)
       (setq locked (cons l locked))
     )
   )
 )

 ;; Now lets explode 'em

 (while (ssget "_X" '((0 . "INSERT")))
   (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))
     (vla-Explode obj)
     (vla-delete obj)
   )
   (vla-delete ss)
 )  

 ;; ReLock the Layers

 (mapcar
   (function
     (lambda ( l ) (vla-put-lock l :vlax-true))
   )
   locked
 )

 ;; End the Undo mark

 (_EndUndo doc)
 
 ;; Exit Cleanly

 (princ)
)
   
   

Link to comment
Share on other sites

Lee

 

Appreciate the help on this. Been out of the office since I posted the thread.

 

The issue that I have is that the blocks that aren't getting exploded is prefixed with an example: *E118. If I call this up using the 'Explodable' property feature these blocks don't give me the ability to change it.

 

In investigating the original drawing these objects are not blocks until I insert it in to a new drawing. If I could just ignore them I would get the results that I need.

 

Thanks...G

Link to comment
Share on other sites

Ok, try this instead:

 

(defun c:ExplodeAllBlocks ( / *error* _StartUndo _EndUndo doc locked ss )
 (vl-load-com)
 ;; © Lee Mac 2010

 ;; Error Handler

 (defun *error* ( msg )
   (if locked
     (mapcar
       (function
         (lambda ( l )
           (vl-catch-all-apply 'vla-put-lock (list l :vlax-true))
         )
       )
       locked
     )
   )
   (if doc (_EndUndo doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (defun _StartUndo ( doc ) (_EndUndo doc)
   (vla-StartUndoMark doc)
 )

 (defun _EndUndo ( doc )
   (if (= 8 (logand 8 (getvar 'UNDOCTL)))
     (vla-EndUndoMark doc)
   )
 )

 ;; Start an Undo Mark

 (_StartUndo
   (setq doc
     (vla-get-ActiveDocument
       (vlax-get-acad-object)
     )
   )
 )

 ;; Unlock all Layers

 (vlax-for l (vla-get-layers doc)
   (if (eq :vlax-true (vla-get-lock l))
     (progn
       (vla-put-lock l :vlax-false)
       (setq locked (cons l locked))
     )
   )
 )

 ;; Now lets explode 'em

 (if (ssget "_X" '((0 . "INSERT")))
   (progn
     (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))
       (if (vl-catch-all-error-p
             (vl-catch-all-apply 'vla-Explode (list obj))
           )
         (princ (strcat "\n** Unable to Explode Block: " (vla-get-name obj) " **"))
         (vla-delete obj)
       )
     )
     (vla-delete ss)
   )
 )  

 ;; ReLock the Layers

 (mapcar
   (function
     (lambda ( l ) (vla-put-lock l :vlax-true))
   )
   locked
 )

 ;; End the Undo mark

 (_EndUndo doc)
 
 ;; Exit Cleanly

 (princ)
)

Link to comment
Share on other sites

Thought I would post some of my other findings.....after further looking into the drawing I've found that the objects being reported as blocks are actually 'Wipeout' frames and groups which is why not all blocks where being exploded.:shock:

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