If I understand well you want to switch autocad layout from external application?
Firstly you need to get AutoCAD Instance: (below code for AutoCAD 2022)
public static AcadApplication GetAcadApplication(bool CreateNewIfNotLaunched)
{
AcadApplication acApp = null;
const string strProgId = "AutoCAD.Application.24.1";
try
{
acApp = (AcadApplication)Marshal.GetActiveObject(strProgId);
}
catch
{
if (CreateNewIfNotLaunched == true)
{
try
{
acApp = new AcadApplication();
}
catch
{
// If an instance of AutoCAD is not created then message and exit
System.Windows.Forms.MessageBox.Show("Instance of 'AutoCAD.Application'" +
" could not be created.");
}
}
}
return acApp;
}
then you can send command to Autocad:
public static void SendCommandToCAD(object sender, EventArgs e, string command)
{
AcadApplication CAD = GetAcadApplication(false);
if (CAD != null)
{
// wait for AutoCAD is visible
while (true)
{
try { CAD.Visible = true; break; }
catch { }
}
var doc = CAD.ActiveDocument;
doc.SendCommand(command + " ");
}
}