Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Delete and Purge Block by name

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
13417 Views, 6 Replies

Delete and Purge Block by name

I would like to use a lisp routine to open all the files in a selected folder, search for a blocks by name, delete them, purge the drawing, save and close.

 

Is there a routing that can be used to do this?

Tags (3)
6 REPLIES 6
Message 2 of 7
greg_battin
in reply to: Anonymous

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]

Message 3 of 7
Kent1Cooper
in reply to: greg_battin


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

Kent Cooper, AIA
Message 4 of 7
greg_battin
in reply to: Kent1Cooper

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

Message 5 of 7
Lee_Mac
in reply to: Anonymous

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.

 

 

Message 6 of 7
sleepy86
in reply to: Lee_Mac

@Lee Mac : I see it's very helpful your lisp 🙂 Tks
Message 7 of 7

Thanks for sharing.

 

It works better if you modify:
(command "-purge" "B" "YourBlockName" "N" "")

to
(command "-purge" "B" "YourBlockName" "N")

 

on my end.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost