Goal is to bind insert all xrefs in a drawing and then explode them.
The xrefs name begin with either a BL or UT.
The following code works, but not very well...looking for something better.
Have to run this multiply times to get them all: (command "explode" (ssget "_x" '((2 . "BL*,UT*"))))
(defun ARCH:ToggleXrefs-Bind (searchstr / tbldata table_list xrefs match cnt un/load)
(setq tbldata nil
xrefs '()
searchstr (strcase searchstr)
)
;;find all the xrefs in drawing
(while (setq tbldata (tblnext "BLOCK" (not tbldata)))
(if (= 4 (logand 4 (cdr (assoc 70 tbldata))))
(setq xrefs (cons (strcase (cdr (assoc 2 tbldata))) xrefs))
)
)
;;find the first match, if any, for search string
(setq cnt 0)
(while (and xrefs (not match) (< cnt (length xrefs)))
(if (wcmatch (nth cnt xrefs) searchstr)
(setq match (nth cnt xrefs))
)
(setq cnt (1+ cnt))
)
;;if a match was found then go ahead
(if match
(progn
;;assumes the state of the first match is same for all matching xrefs
(setq un/load (if (assoc 71 (entget (tblobjname "block" match)))
"Reload"
"Bind"
)
)
;;do the deed
(princ (strcat "\n" un/load "ing " searchstr))
(command "-xref" un/load searchstr)
)
;;no match found
(princ "\nNo valid xrefs in drawing.")
)
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;(ARCH:ToggleXrefs-Bind "BL*")
;;(ARCH:ToggleXrefs-Bind "UT*")
(defun C:Test ()
(ARCH:ToggleXrefs-Bind "BL*")
;;(ARCH:ToggleXrefs-Bind "UT*")
;;(setq ss (ssget "_x" '((2 . "BL*,UT*"))))
(command "explode" (ssget "_x" '((2 . "BL*,UT*"))))
)