I had a question come in by email about how to find out the full path of a drawing open inside AutoCAD. Here's some C# code that does just this:
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
namespace PathTest
{
public class Commands
{
[CommandMethod("PTH")]
public void DrawingPath()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
HostApplicationServices hs =
HostApplicationServices.Current;
string path =
hs.FindFile(
doc.Name,
doc.Database,
FindFileHint.Default
);
doc.Editor.WriteMessage(
"\nFile was found in: " + path
);
}
}
}
Here's what happens when you run the PTH command, with a file opened from an obscure location, just to be sure:
Command: pth
File was found in: C:\Temp\test.dwg
Update:
Tony Tanzillo wrote in a comment:
I think you could also read the Filename property of the Database to get the full path to the drawing, keeping in mind that if the drawing is a new, unsaved document, the Filename property returns the .DWT file used to create the new drawing.
Thanks, Tony - shame on me for missing the obvious. In my defence, I wrote the post in between meetings in Las Vegas, if that's any excuse. :-)