Message 1 of 2
Autodesk.AutoCAD.Interop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to start AutoCAD using COM Interop but can't get it to work. If I manually start AutoCAD and set the variable "STARTUP" to 3, everything works. If I leave it at the default value of 2, it won't. My AcadApplication is valid but all of the methods throw exceptions. Here's a code snippet:
try { pACADApp = (AcadApplication)Marshal.GetActiveObject(szProgramId); fWasAutoCADRunning = true; } catch (COMException) { try { pACADApp = new AcadApplication(); } catch (Exception) { } } if (pACADApp == null) { Application.Current.Dispatcher.Invoke(() => { string szErrorMsg = string.Format("Failed to create an instance of AutoCAD. Please ensure AutoCAD is properly installed on this computer before processing.\n\nExpected program id: {0}", szProgramId); GenericMessageBox pErrorDlg = new GenericMessageBox("Process Failed", szErrorMsg, GenericMessageBox.MessageBoxButtons.OK, GenericMessageBox.MessageBoxIcon.Error); pErrorDlg.Owner = pMainWindow; pErrorDlg.ShowDialog(); }); return; } this.pProgress.szPrimaryStatus = "Sending AutoCAD command"; // Wait for AutoCAD to finish opening while (true) { try { pACADApp.Visible = true; pACADApp.WindowState = Autodesk.AutoCAD.Interop.Common.AcWindowState.acMin; break; } catch { } }
It fails to clear the "while (true)" loop. pACADApp.Visible throws an exception. In fact, all of the methods of pACADApp throw exceptions.
Any help would be appreciated.
Thanks,
Joe