I just threw this one together.
It will delete all blocks in a drawing (including inside other blocks) and purge the drawing of the block definition.
P=
... I made a couple modifications and uploaded the revised file ...
Code:
;___________________________________________________________________________________________________________
;
; Function for deleting blocks from a drawing.
; Syntax: (blockdelete "detailbub*")
; Written By: Peter Jamtgaard 2014 copyright 2014 all rights reserved
;___________________________________________________________________________________________________________
(defun C:BlockDelete ()
(blockdelete (getstring "\nEnter Block Name: "))
)
(defun BlockDelete (strWCBlockName / objBlock lstBlockDefinitions lstBlockInstances)
(command "layer" "u" "*" "")
(setq strWCBlockName (strcase strWCBlockName))
(vlax-for objBlock (vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)))
(if (wcmatch (strcase (vla-get-name objBlock)) strWCBlockName)
(setq lstBlockDefinitions (cons objBlock lstBlockDefintions))
(vlax-for objItem objBlock
(and
(wcmatch (vla-get-objectname objItem) "AcDbBlockReference,AcdbMInsertBlock")
(wcmatch (strcase (vla-get-name objItem)) strWCBlockName)
(setq lstBlockInstances (cons objItem lstBlockInstances))
)
)
)
)
(apply 'and
lstBlockObjects
(apply 'and (mapcar 'ObjectDelete lstBlockInstances))
(regen)
lstBlockDefinitions
(apply 'and (mapcar 'ObjectDelete lstBlockDefinitions))
)
)
(defun ObjectDelete (objItem)
(errortrap (quote (vla-delete objItem)))
)
(defun Regen ()
(errortrap (quote (vla-regen (vla-get-activedocument (vlax-get-acad-object)) 0)))
)
; Standardized Error Trap
(defun ErrorTrap (symFunction / objError result)
(if (vl-catch-all-error-p
(setq objError (vl-catch-all-apply
'(lambda (X123)(set X123 (eval symFunction)))
(list 'result))))
nil
(if result result 'T)
)
)
(vl-load-com)