Here is a Lisp Routine where you need to swap out the name of you block as noted in the routine.
The below code was modified from the code found in the following link:
http://forums.cadalyst.com/showthread.php?t=6694
~Greg
[code]
(defun c:bke (/ SS1)
(setq SS1 (ssget "X" (list '(0 . "INSERT") (cons 2 "YourBlockName"))))
(command "erase" ss1 "")
(command "-purge" "B" "YourBlockName" "N" "")
(command "_regenall")
(princ)
)
[/code]
@greg_battin wrote:
Here is a Lisp Routine where you need to swap out the name of you block as noted in the routine.
....
(defun c:bke (/ SS1)
(setq SS1 (ssget "X" (list '(0 . "INSERT") (cons 2 "YourBlockName"))))
(command "erase" ss1 "")
(command "-purge" "B" "YourBlockName" "N" "")
(command "_regenall")
....
Be aware that such an approach will remove only such Blocks in the current space. If they might exist in more than one Layout, and/or in both Model and Paper space, and/or if you're stepping through all drawings in a folder and any of the drawings might not open up in the space in which all such Blocks would be inserted, then you would need to step through the selection set and use (entdel) to remove each one, rather than (command "_.erase" ...) on all of them together.
Also, if you're stepping through all drawings in a folder [Search these Forums for various threads about doing that for various purposes], presumably you're closing each drawing after you've removed the Block(s) and Purged the definition, to move on to the next drawing. In that case, the Regeneration would serve no real purpose, but would make the process take a little longer.
Great point Kent.
After some looking around, the routine found in the following thread might be a better solution.
http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Delete-specific-Block/td-p/3780264
It still doesn't perform a batch process but the OP can modify the lisp as needed and then use ScriptPro in order to process a folder.
Thanks
~Greg
My Delete Blocks program will allow you to delete all block references (that is, both standard / dynamic references, primary & nested to any depth) of one or more blocks from a drawing, and will then proceed to remove the corresponding redundant block definitions from the drawing.
The command version of the program will present the user with a simple dialog with a list of block names available for deletion, however, for batch operations, this dialog may be bypassed by calling the 'LM:deleteblocks' function with an appropriate VLA Document Object and a list of block names to be deleted.
Furthermore, the 'LM:deleteblocks' function at the core of the application is also compatible for use in conjunction with an ObjectDBX interface, allowing the user to delete a number of blocks from multiple drawings, without opening such drawings in the AutoCAD Editor (hence, hundreds of drawings may be processed in seconds). I offer an ObjectDBX Wrapper function to facilitate the evaluation of a function on multiple drawings using an ObjectDBX interface.
I hope this helps.
Thanks for sharing.
It works better if you modify:
(command "-purge" "B" "YourBlockName" "N" "")
to
(command "-purge" "B" "YourBlockName" "N")
on my end.