Internal Exception - thrown after having displaying two PreviewController

Internal Exception - thrown after having displaying two PreviewController

Anonymous
Not applicable
1,049 Views
8 Replies
Message 1 of 9

Internal Exception - thrown after having displaying two PreviewController

Anonymous
Not applicable

Hello team,

 

I'm receiving this exception after putting a PreviewController into two different hosts in winforms:

 

temp.jpg

Below is the example code: 

 

elementHost1.Child = new PreviewControl(doc1, viewId);
elementHost2.Child = new PreviewControl(doc2, viewId);

 

 

I also tried this and it failed:

 

PreviewControl control = new PreviewControl(doc, viewId);
elementHost1.Child = control;
elementHost2.Child = control;

 

 

However, if I only have one host active, it works. 

 

Any suggestions on how to solve this? Thanks!

0 Likes
Accepted solutions (1)
1,050 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

RTFM, please.

 

The documentation on the PreviewControl clearly states:

 

https://www.revitapidocs.com/2020/50112279-5c9d-0351-bbd1-698e76be9e36.htm

 

Presents a preview control to browse the Revit model.

 

Remarks

 

The dialog or form or window host this preview control must be modal. The view can be any graphical view but not a non-graphical view. And only one can be active. The view can be manipulated by embedded view cube and the visibility and graphical settings set on the view will be evident in the preview control.

 

That is pretty clear, isn't it?

  



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

0 Likes
Message 3 of 9

Anonymous
Not applicable

I did think of that, but I thought they would throw the "Autodesk.Revit.Exceptions InvalidOperationException - Thrown when there is an active preview control..." exception? or is this for a different exception?

0 Likes
Message 4 of 9

jeremytammik
Autodesk
Autodesk
Accepted solution

You are absolutely correct, it should indeed. 

 

Please submit a minimal reproducible case that I can pass on to the development team:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Afaik, they say that internal exceptions should never make it to the outside world, e.g., an external third-party Revit add-in.

 

As you have noted, though, that does not always hold true...

 



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

0 Likes
Message 5 of 9

Anonymous
Not applicable

Since using two preview controller does not work, I plan to create two new view instead. However, I can't see to find a way to move and resize the view through the api. 

 

I would like to take this:

 
 

temp.jpg

and move it into its own tab and resize it like so:

 

temp.jpg

 

Would that be possible? Thanks!

0 Likes
Message 6 of 9

jeremytammik
Autodesk
Autodesk

Are you saying that you can do that manually in the user interface, and you would like to know whether the same can be achieved programmatically? I am not aware of any programmatic control via the Revit API to layout the user interface views. 

 



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

0 Likes
Message 7 of 9

Anonymous
Not applicable

Yup, I would like to do that to the UI through the api. Unfortunately, as you suggested, it seems like it can't be done.

0 Likes
Message 8 of 9

Anonymous
Not applicable

Is it possible to embed a View inside winforms? Or is that only possible with PreviewControl class due to it inheriting from UserControl?

0 Likes
Message 9 of 9

jeremytammik
Autodesk
Autodesk

No + Yes

 



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

0 Likes