Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Autodesk.AutoCAD.Interop

1 REPLY 1
Reply
Message 1 of 2
CADsoftOrl
854 Views, 1 Reply

Autodesk.AutoCAD.Interop

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

Tags (1)
1 REPLY 1
Message 2 of 2

Hi,

 

Are you getting COM calls rejected error? Have you implemented  IMessageFilter as shown in http://through-the-interface.typepad.com/through_the_interface/2010/02/handling-com-calls-rejected-b...

 

 



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report