Active Member
Posts: 6
Registered: ‎06-24-2011
Message 1 of 2 (381 Views)

X-Ref Listing with RealDwg

381 Views, 1 Replies
08-29-2011 08:17 PM
Is it possible to get a listing of all of the X-Refs contained in a particular document. I am attempting to do this with the following code: db.ReadDwgFile(testFileName, FileOpenMode.OpenForReadAndWriteNoShare, true, null); using (var tx = db.TransactionManager.StartTransaction()) { var xrefGraph = db.GetHostDwgXrefGraph(true); for(int i = 0; i < xrefGraph.NumNodes; i++) { XrefGraphNode xgn = xrefGraph.GetXrefNode(i); Console.WriteLine(xgn.Name); } } I know that this drawing has 3 attached X-Refs, but none are coming up in the node graph. Any ideas of what I may be doing wrong? Thanks and Regards, Sean Hunter
ADN Support Specialist
Posts: 659
Registered: ‎06-02-2009
Message 2 of 2 (353 Views)

Re: X-Ref Listing with RealDwg

09-05-2011 02:46 AM in reply to: shunta17



XRefs are accessed in RealDWG the exact same way than in AutoCAD. You first need to call "Database.ResolveXrefs" and of course to have those referenced documents physically present on your disk. They won't get resolved otherwise...


Here is an AutoCAD command. RealDWG code will be the same, except you don't have Document, Editor and you get the database using HostApplicationServices.WorkingDatabase:


public static void XrefGraph()
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    using (Transaction Tx = db.TransactionManager.StartTransaction())
        db.ResolveXrefs(true, false);

        XrefGraph xg = db.GetHostDwgXrefGraph(true);

        for (int i = 1; i < xg.NumNodes; ++i)
            XrefGraphNode node = xg.GetXrefNode(i);

            if (node.XrefStatus == XrefStatus.Resolved)
                BlockTableRecord btr = Tx.GetObject(node.BlockTableRecordId, OpenMode.ForRead) as BlockTableRecord;


                if (btr.IsFromExternalReference == true)
                    ed.WriteMessage("\nXref path name: " + btr.PathName);

                ed.WriteMessage("\nName of Xref (Found name): " + node.Database.Filename);



Philippe Leefsma
Developer Consultant
Developer Technical Services
Global Subscription & Support



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!