Attached is what I've (used loosely as I've essentially used LM's code and edited a piece of sample code from his website) come up with. It works exactly as expected, but I'd like to figure out how to simply cancel the burst command if no blocks are found. I tried adding it to the if statement, but that makes autocad return an error for too many arguments. I'm probably putting it in the wrong spot. I also decided to use visiblity states instead of multiple blocks, simplifying my search parameter.
Code:
(defun c:ComboBreak (/ blk)
(setq flag (getvar "qaflags"))
(setvar "qaflags" 1)
(setq blk "recep_combo")
(if (tblsearch "BLOCK" blk)
(sssetfirst nil (GetBlockSelection blk))
(princ (strcat "\n" blk " doesn't exist."))
)
(command "explode")
(setvar "qaflags" flag)
(princ)
)
(defun GetBlockSelection (name)
(ssget "_X"
(list
'(0 . "INSERT")
(cons 2
(apply 'strcat
(cons name
(mapcar
(function (lambda (x) (strcat ",`" x)))
(LM:GetAnonymousReferences name)
)
)
)
)
)
)
)
;;--------------=={ Get Anonymous References }==--------------;;
;; ;;
;; Returns the names of all anonymous references of a block. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; name - block name for which to return anon. references ;;
;;------------------------------------------------------------;;
;; Returns: List of Anonymous Block names, else nil if none ;;
;;------------------------------------------------------------;;
(defun LM:GetAnonymousReferences (name / ano def lst rec ref)
(setq name (strcase name))
(while (setq def (tblnext "BLOCK" (null def)))
(if
(and
(= 1 (logand 1 (cdr (assoc 70 def))))
(setq rec
(entget
(cdr
(assoc 330
(entget
(tblobjname
"BLOCK"
(setq ano (cdr (assoc 2 def)))
)
)
)
)
)
)
)
(while
(and
(not (member ano lst))
(setq ref (assoc 331 rec))
)
(if
(and
(entget (cdr ref))
(eq name (strcase (LM:EffectiveName (cdr ref))))
)
(setq lst (cons ano lst))
)
(setq rec (cdr (member (assoc 331 rec) rec)))
)
)
)
(reverse lst)
)
;;----------------=={ Effective Block Name }==----------------;;
;; ;;
;; Returns the effective name of a block. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; blockentity - Block Reference Entity name ;;
;;------------------------------------------------------------;;
;; Returns: True block name as per the block definition ;;
;;------------------------------------------------------------;;
(defun LM:EffectiveName (blockentity / name repbtag)
(if (wcmatch (setq name (cdr (assoc 2 (entget blockentity))))
"`**"
)
(if
(and
(setq repbtag
(cdadr
(assoc -3
(entget
(cdr
(assoc 330
(entget (tblobjname "BLOCK" name))
)
)
'("AcDbBlockRepBTag")
)
)
)
)
(setq repbtag (handent (cdr (assoc 1005 repbtag))))
)
(setq name (cdr (assoc 2 (entget repbtag))))
)
)
name
)