I am, once again, at a loss why something works in one version but not another. This code works great in Acad2010:
[CommandMethod("NewCommand", CommandFlags.Session)]
public void newcommandcommand()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
progFrm = new ProgressForm();
string dwgName = doc.Name + " - edited";
DocumentLock doclock = doc.LockDocument();
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//edit a bunch of stuff in the drawing
tr.Commit();
}
try
{
db.SaveAs(dwgName, DwgVersion.Current);
}
catch
{
ed.WriteMessage("\nDrawing edited but unable to save. Please perform a manual save if desired.");
}
if (File.Exists(dwgName))
{
Document newdoc = Application.DocumentManager.Open(dwgName, false);
Application.DocumentManager.MdiActiveDocument = newdoc;
doc.CloseAndDiscard();
newdoc.Editor.WriteMessage("\nDrawing edited and saved as: " + dwgName);
Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();
}
}
However, in 2011 it throws a "Drawing is busy" exception. And, worse, in 2012 it throws a Fatal Error and shuts down. In both cases it fails at the "doc.CloseAndDiscard()" line. Anyone see what I'm missing to be able to close the drawing in which the command started?