.NET

Reply
Active Member
a.hajihasani
Posts: 6
Registered: ‎08-28-2012
Message 1 of 4 (405 Views)
Accepted Solution

Drawing Open issue

405 Views, 3 Replies
01-14-2014 05:38 AM

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.DocumentManager;
            doccol.Open(DropDownList_dwgs.Items[DropDownList_dwgs.SelectedIndex].ToString(), false);
        }

 

Running the code leads to the following exception:

Invalid execution context.

 

Any help would be appreciated.

 

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).

*Expert Elite*
norman.yuan
Posts: 1,045
Registered: ‎04-27-2009
Message 2 of 4 (396 Views)

Re: Drawing Open issue

01-14-2014 06:22 AM in reply to: a.hajihasani

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).

Active Member
a.hajihasani
Posts: 6
Registered: ‎08-28-2012
Message 3 of 4 (364 Views)

Re: Drawing Open issue

01-14-2014 09:09 PM in reply to: a.hajihasani

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?

*Expert Elite*
norman.yuan
Posts: 1,045
Registered: ‎04-27-2009
Message 4 of 4 (334 Views)

Re: Drawing Open issue

01-15-2014 07:16 AM in reply to: a.hajihasani

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.ShowModelessDialog() to open the forms? Do you code it correctly to make sure the modeless form is a static/singleton instance?

 

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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!