I've been using this VB.NET code to check for existing instance of AutoCAD and use it or open a new one if none exists:
Dim vAcadApp As AcadApplication
Dim vAcadDoc As AcadDocument
Try
If Process.GetProcessesByName("acad").Length > 0 Then
vAcadApp = GetObject(, "AutoCAD.Application.19")
Else
vAcadApp = New AcadApplication
End If
vAcadApp.Visible = True
vAcadApp.WindowState = AcWindowState.acMax
vAcadDoc = vAcadApp.Documents.Open(DwgPath & DwgName, True)
I need to convert this over to C# and so far I've only got this part working:
using System;
using AutoCAD;
class LaunchAutoCAD1
{
public static void StartACAD(string vFilename)
{
AcadApplication vAcadApp;
AcadDocument vAcadDoc;
try
{
vAcadApp = new AcadApplication();
vAcadApp.Visible = true;
vAcadApp.WindowState = AcWindowState.acMax;
vAcadDoc = vAcadApp.Documents.Open(vFilename,true);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
}
}
This works but unfortunately I seem to be having touble with the GetObject method to check if AutoCAD is already running. I've searched and searched and keep finding only VB.NET code or the same question by someone else which no one ever answered. Any advice would be appreciated.