.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Drawing Open issue

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
a.hajihasani
733 Views, 3 Replies

Drawing Open issue

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.

 

3 REPLIES 3
Message 2 of 4
norman.yuan
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).

Message 3 of 4
a.hajihasani
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?

Message 4 of 4
norman.yuan
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.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost