.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Xref - GetFullPathname (i.e "C:\folder1\folder2\Xref.dwg")

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
VB_Autocad_guy
1274 Views, 8 Replies

Xref - GetFullPathname (i.e "C:\folder1\folder2\Xref.dwg")

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

8 REPLIES 8
Message 2 of 9
Artvegas
in reply to: VB_Autocad_guy

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

Message 3 of 9
TJK77
in reply to: Artvegas

BlockTableRecord has the PathName property.

Message 4 of 9
Artvegas
in reply to: TJK77

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.

Message 5 of 9
TJK77
in reply to: Artvegas

Thank you for the tip Artvegas!

Message 6 of 9
TJK77
in reply to: Artvegas

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

Message 7 of 9
Artvegas
in reply to: VB_Autocad_guy

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);
			}
		}
	}
}

 

Message 8 of 9
TJK77
in reply to: Artvegas

Does the BlockTableRecord have to be open for write? I have mine open for read. That is probably the issue.

Message 9 of 9
Artvegas
in reply to: VB_Autocad_guy

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.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost