Hi,
I'm trying to make a batch process and I want to trap any possible situation:
- the file is the active document
- the file is opened but not active
- the file is closed
It works fine excepted if the document is opened in another AutoCAD session than the one from where the process is launched: the document doesn't owns to the DocumentCollection so it's dealed as a closed one and I got an eFileAccessErr exception when trying to invoke Database.SaveAs.
Here's what I wrote:
private void ProcessDatabase(string filename)
{
DocumentCollection docMan = acadApp.DocumentManager;
Database db = null;
if (docMan.MdiActiveDocument.Name == filename)
{
db = docMan.MdiActiveDocument.Database;
DoIt(db);
db.SaveAs(filename, DwgVersion.Current);
}
else
{
foreach (Document doc in docMan)
{
if (doc.Name == filename)
{
using (DocumentLock docLock = doc.LockDocument())
{
db = doc.Database;
DoIt(db);
}
doc.CloseAndSave(filename);
}
}
if (db == null)
{
using (db = new Database(false, true))
{
db.ReadDwgFile(filename, System.IO.FileShare.ReadWrite, true, string.Empty);
DoIt(db);
db.SaveAs(filename, DwgVersion.Current);
}
}
}
}