Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everybody.
I want to get an AutoCAD.Application instance.
However, an error occurs when GetActiveObject() is executed during the AutoCAD loading screen.
If I set a breakpoint and call GetActiveObject() after loading is finished, the instance is got well.
Is there an event or other method in .Net to use when the loading window ends?
internal class Program
{
static void Main(string[] args)
{
AcadApplication objAcad = default(AcadApplication);
const string strProgId = "AutoCAD.Application.24.1";
Process myProcess = new Process();
myProcess.StartInfo.FileName = @"C:\Program Files\Autodesk\AutoCAD 2022\" + "acad.exe";
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcess.Start();
try
{
objAcad = Marshal.GetActiveObject(strProgId) as AcadApplication;
if (objAcad is null)
throw new Exception("obj is null");
}
catch(Exception ex) // An error occurs if no instance is running
{
Type acType = Type.GetTypeFromProgID(strProgId);
objAcad = (AcadApplication)Activator.CreateInstance(acType, true);
}
objAcad.Visible = true;
}
}
Solved! Go to Solution.