I have made some changes based on our needs here. My modifications will allow for changing plot styles of the xrefs (when applicable) and allow for optionally changing nested xrefs as well (thanks to another one of T. Willey's routines). This also allows you to choose multiple xrefs without having to choose all xrefs and the only nested xref layers that will be changed are those that are nested within the selected xrefs, but all instances of that nested xref will be updated.
; Original by T.Willey at http://www.theswamp.org/index.php?topic=35168.0
; Modified by cmwade77 to allow for selecting multiple xrefs as well as nested xrefs (as an option) and Plotystyle when available
(defun c:xradjust (/ ActDoc Sel Data XrName xRefs ct i ct2)
; Change all the layers of an xref to selected color.
(vl-load-com)
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vla-EndUndoMark ActDoc)
(vla-StartUndoMark ActDoc)
(if (= Clr nil)
(setq Clr 8)
)
(if (= nested nil)
(setq nested "Yes")
)
(if (= pstyle nil)
(setq pstyle "No Change")
)
(setq kWord T)
(while (/= kWord nil)
(cond
((= (getvar "PSTYLEMODE") 0)
(initget "Color Plotstyle Nested _Color PS Nested")
(setq kWord (getkword (strcat "\nColor: " (rtos clr 2 0) "/Plotstyle: " pstyle "/Nested: " nested " <Press Enter to Continue>: ")))
)
(T
(initget "Color Nested _Color Nested")
(setq kWord (getkword (strcat "\nColor: " (rtos clr 2 0) "/Nested: " nested " <Press Enter to Continue>: ")))
)
)
(cond
((= kWord "Color")
(setq Clr (acad_colordlg 8))
)
((= kWord "Nested")
(initget 1 "Yes No")
(setq nested (getkword "\nDo you want to include nested xrefs? (Yes/No) "))
)
((= kWord "PS")
(setq pstyle (getstring T "\nType plotstyle to use (No Change): "))
)
)
)
(while (= xRefs nil)
(setq xRefs (ssget))
)
(setq ct 0)
(while (< ct (sslength xRefs))
(setq Sel (ssname xRefs ct))
(setq ct (+ ct 1)
Data (entget Sel))
(if (= (cdr (assoc 0 Data)) "INSERT")
(progn
(setq XrName (cdr (assoc 2 Data)))
(cond
((= nested "Yes")
(setq MyList nil)
(nxr XrName)
)
)
(if (equal (logand (cdr (assoc 70 (tblsearch "block" XrName))) 4) 4)
(vlax-for i (vla-get-Layers ActDoc)
(if (wcmatch (vla-get-Name i) (strcat XrName "|*"))
(progn
(vla-put-Color i Clr)
(cond
((and (= (getvar "PSTYLEMODE") 0) (/= (strcase pstyle) "NO CHANGE"))
(vla-put-plotstylename i pstyle)
)
)
)
)
(cond
((= nested "Yes")
(setq ct2 0)
(while (< ct2 (length MyList))
(if (wcmatch (vla-get-Name i) (strcat (nth ct2 MyList) "|*"))
(progn
(vla-put-Color i Clr)
(cond
((and (= (getvar "PSTYLEMODE") 0) (/= (strcase pstyle) "NO CHANGE"))
(vla-put-plotstylename i pstyle)
)
)
)
)
(setq ct2 (+ ct2 1))
)
)
)
)
)
)
)
)
(vla-Regen ActDoc acActiveViewport)
(vla-EndUndoMark ActDoc)
(princ)
)
; The code below has been adapted from:
; T. Willey's Code at http://www.theswamp.org/index.php?topic=34277.0
(defun nxr ( xr / GetXrefNesting PrintNestedList )
; Prints nested xref tree to command line, no matter how deep the nesting.
(defun GetXrefNesting (/ GetXrefInfo tempData tempEnt XrefList NonNestedXrefList NestedXrefList )
(defun GetXrefInfo ( ent / NestList )
(foreach i (member '(102 . "{BLKREFS") (entget ent))
(if (equal (car i) 332)
(progn
(setq NestedList (cons (cdr i) NestedList))
(setq NestList
(cons
(cons
(cdr i)
(GetXrefInfo (cdr i))
)
NestList
)
)
)
)
)
NestList
)
;-------------------------------------
(while (setq tempData (tblnext "block" (not tempData)))
(if (equal (logand (cdr (assoc 70 tempData)) 4) 4)
(progn
(setq tempEnt (tblobjname "block" (cdr (assoc 2 tempData))))
(setq tempEnt (cdr (assoc 330 (entget tempEnt))))
(setq XrefList
(cons
(cons
tempEnt
(GetXrefInfo tempEnt)
)
XrefList
)
)
)
)
)
(foreach i XrefList
(if (not (member (car i) NestedList))
(setq NonNestedXrefList (cons i NonNestedXrefList))
)
)
NonNestedXrefList
)
;------------------------------------------------
(defun PrintNestedList ( lst spc )
(foreach
i
(vl-sort
lst
(function
(lambda ( a b )
(<
(strcase (cdr (assoc 2 (entget (car a)))))
(strcase (cdr (assoc 2 (entget (car b)))))
)
)
)
)
(setq NX (cdr (assoc 2 (entget (car i)))))
(if (= MyList nil)
(setq MyList (list NX))
(setq MyList (append MyList (list NX)))
)
;(prompt (strcat "\n" spc " Nested xref: " (cdr (assoc 2 (entget (car i))))))
(PrintNestedList (cdr i) (strcat " " spc))
;(PrintNestedList (cdr i) (strcat " |" spc)) ; second option shown below
)
)
;-----------------------------------------------------
(foreach
i
(vl-sort
(GetXrefNesting)
(function
(lambda ( a b )
(<
(strcase (cdr (assoc 2 (entget (car a)))))
(strcase (cdr (assoc 2 (entget (car b)))))
)
)
)
)
(if (= xr (cdr (assoc 2 (entget (car i)))))
(progn
;(prompt (strcat "\n Main xref: " (cdr (assoc 2 (entget (car i))))))
(PrintNestedList (cdr i) " |-")
)
)
)
(princ)
)
<edit CAB: replaced tabs with 3 spaces>