ggarcia Posted October 6, 2010 Share Posted October 6, 2010 (edited) 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 May 30, 2014 by SLW210 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 6, 2010 Share Posted October 6, 2010 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 6, 2010 Share Posted October 6, 2010 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 6, 2010 Share Posted October 6, 2010 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) ) Quote Link to comment Share on other sites More sharing options...
ggarcia Posted October 8, 2010 Author Share Posted October 8, 2010 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 8, 2010 Share Posted October 8, 2010 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) ) Quote Link to comment Share on other sites More sharing options...
ggarcia Posted October 8, 2010 Author Share Posted October 8, 2010 Lee That gave me exactly what I needed..... Appreciate the help....G Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 8, 2010 Share Posted October 8, 2010 Happy to help G Quote Link to comment Share on other sites More sharing options...
ggarcia Posted October 8, 2010 Author Share Posted October 8, 2010 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. Quote Link to comment Share on other sites More sharing options...
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.