try this:
Code:
; GetXrfLst function given name of xref returns list of nested xref names if any
; Examples:
; (load "GetXrfLst")
; (setq lst (GetXrfLst "Xref Name")) ; where "Xref Name" is name of top level Xref in current dwg
; Returns:
; nil ; if no nested xrefs found
; ("Elevator Bank 4" "Stair U") ; sorted list of nested xref names
; To get xref path of first element:
; (cdr (assoc 2 (tblsearch "BLOCK" (nth 0 lst))))
;
(defun GetXrfLst (xrf / _nestedxrefs lst)
(vl-load-com)
; _nestedxrefs function given tblobjname of block xref name
; Returns list of nested xrefs if any
; From Lee Mac
; http://www.theswamp.org/index.php?topic=55684.0
(defun _nestedxrefs ( blk / enx rtn xrn )
(while (setq blk (entnext blk))
(if (and (setq enx (entget blk))
(= "INSERT" (cdr (assoc 0 enx)))
(setq xrn (cdr (assoc 2 enx)))
(= 4 (logand 4 (cdr (assoc 70 (tblsearch "BLOCK" xrn)))))
(not (member xrn rtn))
)
(setq rtn (cons xrn rtn))
)
)
rtn
)
(if
(and
(tblsearch "BLOCK" xrf) ; if xref name exists in block table
(setq lst (_nestedxrefs (tblobjname "BLOCK" xrf))) ; get nested xrefs
)
(vl-sort lst '<) ; return sorted list in ascending order
)
) ; defun