List xrefs loaded in the drawing

Here one way to do it with python.

import clr

clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')

from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *

adoc = Application.DocumentManager.MdiActiveDocument

xrefs = []

with adoc.LockDocument():
	with adoc.Database as db:
		with db.TransactionManager.StartTransaction() as t:
			bt = t.GetObject(db.BlockTableId, OpenMode.ForRead)
			btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead)

			for oid in btr:
				bl = t.GetObject(oid, OpenMode.ForRead)
				if isinstance(bl, BlockReference):
					if bl.BlockTableRecord.IsFromExternalReference:
						xrefs.append(bl.Name)
						
			
OUT = xrefs
5 Likes