.NET

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

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

497 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

Distinguished Contributor
Artvegas
Posts: 104
Registered: ‎04-21-2011
Message 2 of 9 (482 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 (452 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 (436 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 (412 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 (402 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 (390 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 (374 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 (366 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community