.NET

.NET

Reply
Distinguished Contributor
136 Posts
5 Kudos
Registered: ‎07-24-2009
Post 1 of 9
Accepted Solution

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

581 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
104 Posts
11 Kudos
Registered: ‎04-21-2011
Post 2 of 9

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
14 Posts
0 Kudos
Registered: ‎03-22-2012
Post 3 of 9

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
104 Posts
11 Kudos
Registered: ‎04-21-2011
Post 4 of 9

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
14 Posts
0 Kudos
Registered: ‎03-22-2012
Post 5 of 9

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
14 Posts
0 Kudos
Registered: ‎03-22-2012
Post 6 of 9

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
104 Posts
11 Kudos
Registered: ‎04-21-2011
Post 7 of 9

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
14 Posts
0 Kudos
Registered: ‎03-22-2012
Post 8 of 9

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
104 Posts
11 Kudos
Registered: ‎04-21-2011
Post 9 of 9

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 interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!