.NET

Reply
Distinguished Contributor
VB_Autocad_guy
Posts: 136
Registered: ‎07-24-2009
Message 1 of 9 (563 Views)
Accepted Solution

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

563 Views, 8 Replies
07-05-2012 08:26 AM

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

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

Distinguished Contributor
Artvegas
Posts: 104
Registered: ‎04-21-2011
Message 2 of 9 (548 Views)

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

07-05-2012 12:57 PM 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

Contributor
TJK77
Posts: 14
Registered: ‎03-22-2012
Message 3 of 9 (518 Views)

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

07-06-2012 09:01 AM in reply to: Artvegas

BlockTableRecord has the PathName property.

Distinguished Contributor
Artvegas
Posts: 104
Registered: ‎04-21-2011
Message 4 of 9 (502 Views)

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

07-07-2012 01:19 AM 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.

Contributor
TJK77
Posts: 14
Registered: ‎03-22-2012
Message 5 of 9 (478 Views)

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

07-09-2012 05:50 AM in reply to: Artvegas

Thank you for the tip Artvegas!

Contributor
TJK77
Posts: 14
Registered: ‎03-22-2012
Message 6 of 9 (468 Views)

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

07-09-2012 03:48 PM 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

Distinguished Contributor
Artvegas
Posts: 104
Registered: ‎04-21-2011
Message 7 of 9 (456 Views)

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

07-10-2012 12:55 AM 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);
			}
		}
	}
}

 

Contributor
TJK77
Posts: 14
Registered: ‎03-22-2012
Message 8 of 9 (440 Views)

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

07-11-2012 06:18 AM in reply to: Artvegas

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

Distinguished Contributor
Artvegas
Posts: 104
Registered: ‎04-21-2011
Message 9 of 9 (432 Views)

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

07-11-2012 10:24 AM 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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
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!