How do I get the full Xref Path name instead of Xref.dwg?
I'm scratching my head is this totally under my nose... cause I don't see where the property is stored.
I'm getting EV_BDR.dwg instead of C:\folder\EV_BDR.dwg
Solved! Go to Solution.
The BlockTableRecord.Name property returns the xref file path, but not necessarily the full path. It depends on whether the xref is placed with a full path, relative path or no path.
Instead try using the BlockTableRecord.GetXrefDatabase().Filename property. This will give you the full path regardless of the xref path type.
If you are using the xref graph, you would use XrefGraphNode.Database.Filename.
Art
The BlockTableRecord.PathName property returns the xref path in a format dependant upon on whether the xref is placed with a full path, relative path or no path. Whereas BlockTableRecord.GetXrefDatabase().Filename always returns the full path to the xref, irrespective of how the xref path has been specified.
How are you using btr.GetXrefDatabase to derive the full path to a BlockTableRecord. I tried using this bit of code, but it crashes AutoCAD?
Dim xrefLoc As String = btr.GetXrefDatabase(True).Filename.ToString
Below is a sample. Run this in a drawing that contains xrefs. I use it with AutoCAD 2012 and haven't had any problems.
[CommandMethod("ListXrefPaths")] public static void ListXrefPaths() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; using (Transaction tr = db.TransactionManager.StartTransaction()) { // Iterate block table. BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite); foreach (ObjectId id in bt) { // Get block table record. BlockTableRecord btr = (BlockTableRecord)tr.GetObject(id, OpenMode.ForWrite); // Check if block table record is for an xref. if (btr.IsFromExternalReference) { // Output summary to command-line. ed.WriteMessage( "\n* Name: {0}" + "\n Path: {1}" + "\n Full Path: {2}", btr.Name, btr.PathName, btr.GetXrefDatabase(true).Filename); } } } }
Sorry I should have specified both the BlockTable and BlockTableRecords to be opened with OpenMode.ForRead.
The code will work the same, and changing this to ForRead shouldn't result in an AutoCAD crash. I tried both and had no problem.
Can't find what you're looking for? Ask the community or share your knowledge.