Hi every body.
I'm trying to open a drawing using code, but I get some exception at runtime. I've been searching the forum for an hour but seems that the code must be alright.
Here is my code:
private void Button_opendwg_Click(object sender, EventArgs e)
DocumentCollection doccol = Autodesk.AutoCAD.ApplicationServices.Application.D
Running the code leads to the following exception:
Invalid execution context.
Any help would be appreciated.
Solved! Go to Solution.
The code you showed is not enough to identify the exact reason of the exception you ran into. You need to describe a bit more details. such as where the button being clicked sits, a modal dialog box or a modeless dialog box (or a custom paletteset).
If the button being clicked is on a modal dlaog form, then the exception is expected: with a modal dialog box being opened, you cannot open another drawing in AutoCAD editor. This is different from VBA (if you have done similar thing in VBA).
Thank's dear norman, that's it. I changed my code to use modeless dialogs instead, and drawing is opened regularly, but another problem exists:
I've used a windows form as a Main form, which includes some other forms as dialogs. The code I inserted, places in one of these dialogs and when I press the button, drawing is opened, but the dialog form (which includes the button) is closed. What I have to do then?
How do you open the first (main) form? Are you saying that you first open first form as modeless dialog, and then clicking a button on the first form opens another modeless form, which has a button for opening a drawing? Do you use Autodesk.AutoCAD.ApplicationServices.Application.S
Remember you are opening form/dialog inside an desktop application AutoCAD. opening a modeless form on top another modeless form likely confuses the user, and certainly certainly make your code very difficult to manage an singleton instance of the form. I'd rethink the workflow to avoid open another modeless form from an already opened one.
With that said, I did a quick try to open second modeless dialog from the first one and then open a new drawing int AutoCAD from the second form. It works: the 2 modeless form remain open after the drawing being opened. Again, I would not use this kind of workflow, even it works.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register