Hi Norman,
Thanks for the answer, that explains more.
Right now I'm using the Session flag on the command but the opening and closing the drawing part is being performed on a separate controller class.
Maybe I need to have that piece of code withing the Command method? Does that makes any sense?
This is the code withing the method
[CommandMethod("TestBatch", CommandFlags.Session)]
public void TestBatch()
{
MyController oController = new MyController(_AppLogger);
OpenFileDialog dialog = new OpenFileDialog {
DefaultExt = ".dwg",
Multiselect = true,
Filter = "dwg files|*.dwg",
};
Nullable<bool> result = dialog.ShowDialog();
if (result == true)
{
try
{
oController.Start(dialog.FileNames);
}
catch (System.Exception e)
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(e.StackTrace);
}
}
}
this is the function in the Controller class
public void Start(string[] drawings)
{
Drawings.AddRange(drawings);
//Start processing the drawings without issues
foreach (string s in Drawings)
{
//Document doc = Application.DocumentManager.MdiActiveDocument;
DocumentCollection docCollection = Application.DocumentManager;
Document doc = null;
_RpuId = string.Empty;
_FlId = string.Empty;
if (IOFile.Exists(s))
{
if (!AddDrawing(s, Drawings.Count > 1).ResultValue)
continue;
//Open drawing or use current opened drawing
if (!Application.DocumentManager.MdiActiveDocument.Name.Equals(s))
{
doc = docCollection.Open(s, false);
Application.DocumentManager.MdiActiveDocument = doc;
}
else doc = Application.DocumentManager.MdiActiveDocument;
GlobalLogger.Info(string.Format("Start tagging drawing: {0}", s));
}
else
{
GlobalLogger.Info(string.Format("File {0} does not exist.", s));
return;
}
ProcessDrawing(s);
//Save document
try
{
var obj = CadHelper.GetSystemVariable("DWGTITLED");
if (doc != null && System.Convert.ToInt16(obj) == 0)
{
// Save the active drawing
doc.Database.SaveAs(s, true, DwgVersion.Current,
doc.Database.SecurityParameters);
doc.CloseAndDiscard();
}
}
catch (System.Exception e)
{
GlobalLogger.Error(string.Format("Couldn't save drawing {0}, {3}exception {1}{3}{2}",
s, e.Message, e.StackTrace, Environment.NewLine));
}
}
}