walkinside / sdk

Develop powerful desktop and web applications on top of Walkinside 3D engine
4 stars 4 forks source link

How to open Plugin window automatically on Walkinside start #25

Closed kkneip closed 7 years ago

kkneip commented 7 years ago

When running the following code either in CreatePlugin or in OnProjectOpen event no form will be created/opened. In the described case OpenForm function returns "null".

var form = this.Viewer.UI.OpenForm(typeof(ReceiverForm), this.MessageBus);

When opening another project after Walkinside has been successfully opened anything works fine.

The reason to do so is to open a specific plugin on startup without any user interaction. Are there any other events to consider? Any ideas?

andgonro commented 7 years ago

Hello @kkneip, @kveretennicov will come with a more detailed explanation if there is a way to open a form on project loading. The problem you are facing is that the layout loading is done after the form is loaded and your form gets closed to meet the layout. The way to achieve what you want at this point is to open manually your form and then save the layout; Windowing|Layout|save|default. From this moment your form will be opened as soon as the project is loaded. You will need to do this for all the projects as the layout is stored per project

kveretennicov commented 7 years ago

Sorry, it took longer than I expected to get to this issue. I had a bit of time last week to look into it, although not enough for detailed analysis.

I could confirm that OpenForm neither fails nor opens the form when called from CreatePlugin handler. I was able to work around that by attaching a handler to Application.Idle, so that OpenForm call is postponed:

CreatePlugin(IVRViewerSdk viewer)
{
    ...
    this.m_viewer = viewer;
    Application.Idle += this.OpenFormOnce; 
}

void OpenFormOnce(object sender, EventArgs args)
{
    Application.Idle -= this.OpenFormOnce;
    this.m_viewer.UI.OpenForm(...);
}

Can you try if it works for you? Alternatively, try saving layout like @andgonro suggested. It won't be a code-level solution, but will do the trick still.

kkneip commented 7 years ago

Hi @kveretennicov,

your proposed workaround worked for me. Thanks a lot!