using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;
namespace SwitchDocumentSample
{
public class Commands
{
[CommandMethod("Test", CommandFlags.Session)]
public void Test()
{
string fileName = @"C:\room.dwg";
OpenAndActivateDocument(fileName);
}
public void OpenAndActivateDocument(string fileName)
{
DocumentCollection docs = AcAp.DocumentManager;
Document doc;
try
{
doc = docs.Open(fileName);
}
catch (System.Exception exn)
{
AcAp.ShowAlertDialog(exn.Message);
return;
}
docs.MdiActiveDocument = doc;
using (doc.LockDocument())
{
// rather than: doc.SendStringToExecute("StartAction ", false, false, true);
StartAction();
}
}
[CommandMethod("StartAction")]
public void StartAction()
{
Document doc = AcAp.DocumentManager.MdiActiveDocument;
AcAp.ShowAlertDialog(string.Format("Active document:\n{0}", doc.Name));
}
}
}