This is part of a post I did over at AUGI, and wanted to share it as I learned something new, and figured it could help people here. It may need to be tested more, as I don't use nested xrefs, so I don't have a lot to test this on, but it worked on my small test drawing.
Found out something interesting, and figured I'd code it up real quick. This will get all the xrefs within the drawing. It will list all the inserts of said xref, and will list the xrefs that are nested within it. At least it did on my small test. It returns a list of list of enames. The first ename is the xref definition. Then next list within that list will be the list of inserts. The next list will be the list of nested block table record for the xrefs that are nested.
(defun GetXrefs (/ tempData tempEnt XrefList)
(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 tempData (entget (cdr (assoc 330 (entget tempEnt)))))
(setq XrefList
(cons
(cons
tempEnt
(
(lambda ( x / InsList NestList )
(foreach i x
(cond
((equal (car i) 331)
(setq InsList (cons (cdr i) InsList))
)
((equal (car i) 332)
(setq NestList (cons (cdr i) NestList))
)
)
)
(list InsList NestList)
)
(member '(102 . "{BLKREFS") tempData)
)
)
XrefList
)
)
)
)
)
XrefList
)
Command: (setq lst (GetXrefs))
((<Entity name: 7ed545c0> nil nil) (<Entity name: 7ed54530> (<Entity name:
7ed54548>) (<Entity name: 7ed545b8>)) (<Entity name: 7ed54500> (<Entity name:
7ed54520>) nil))
No inserts for nested xrefs
(<Entity name: 7ed545c0> nil nil)
One insert, no nested xrefs
(<Entity name: 7ed54500> (<Entity name: 7ed54520>) nil)
One insert, one nested xref
(<Entity name: 7ed54530> (<Entity name: 7ed54548>) (<Entity name: 7ed545b8>))
Hope that all makes sense.