About modeless dialogs are automatically released

About modeless dialogs are automatically released

564538157
Contributor Contributor
963 Views
3 Replies
Message 1 of 4

About modeless dialogs are automatically released

564538157
Contributor
Contributor

I wrote a plugin last year that copied the element types from one document to another, and it worked fine at the time, but now there is a problem.

-----------------------------------------------------------------

The simulation steps are as follows:
1Open a revit document “1.rvt”;
2. Open a modeless dialog box;
3Create a new revit document “2.rvt”;
4Close the document “2.rvt”;
At this time, the modeless dialog is closed;

-----------------------------------------------------------------

The program reports an error:
Unable to access the released object, -2146232798

-----------------------------------------------------------------

What is the solution?
Thank you!

0 Likes
964 Views
3 Replies
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk

If you are using the Revit API from a modeless context, you are creating an illegal state that will lead to crashes such as the one you describe and may fatally corrupt your data and your user's models.

 

The Revit API can only be used inside a valid Revit API context, and not from a modeless context:

 

 

Here are some workarounds for obtaining a valid Revit API context from a modeless one:

 

 

Cheers,

 

Jeremy

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 4

564538157
Contributor
Contributor

But I didn't write any code in the modeless dialog, just opened a modeless dialog in the ExternalCommand and still caused the program to crash when I closed 2.rvt.

 

1.png2.png3.png

0 Likes
Message 4 of 4

564538157
Contributor
Contributor

Correct it:
The program does not crash. It automatically releases the modeless dialog when closing 2.rvt. The program enters the Dispose method of Form1 when debugging. This is not what I want.

0 Likes