Hello,
I have noticed that rhino creates a new panel on loading a file, can I prevent that? It breaks my plugin thats keeping track of current objects in the document, my backend code works after loading a file, but the ui is not updating.
You need to give a bit more detail - which panel is newly created upon loading?
What file and file type is being loaded?
my registered eto panel, the OnLoad method is called on loading a 3dm file via the open command
You may want to subscribe to the RhinoApp.Idle
event, and handle any necessary UI updates there. Of course you can track the changes in the document in the OnLoad
but any changes to the UI must be done in the Idle event. So if you need to change anything, subscribe to RhinoApp.Idle
, and if that event handler is triggered, unsubscribe from the event and update your UI as needed. I hope that makes sense
I might not have explained myself well enough, I am able to track the objects, my ui is updating as expected until I load a new 3dm file into rhino, after that my ui is not updating as if a new panel was created, I believe after the file load there are two instances of my plugin
Hi @Vojta_Hanzlík,
This is how panels behave. Knowing this, your panel’s view model should take this into account.
RhiinoCommon exposes many event related to document activity.
https://developer.rhino3d.com/api/rhinocommon/rhino.rhinodoc#events
Perhaps watching for RhinoDoc.CloseDocument events and taking the required action would help?
– dale
I have encountered a similar problem. The Eto Panel example puts the RegisterPanel and OpenPanel in a command. I wanted to make the plug-in installation more intuitive, such that the Panel is automatically visible on loading the plug-in without the user needing to know to type the command.
I initially put both RegisterPanel and OpenPanel in OnLoad like so:
protected override LoadReturnCode OnLoad(ref string errorMessage)
{
//Register the main view panel
var panel_id = typeof(Views.Panel).GUID;
Panels.RegisterPanel(Instance, typeof(Views.Panel), "MyPanel", Properties.Resources.MyLogo);
if (!Panels.IsPanelVisible(panel_id))
{
Panels.OpenPanel(panel_id);
}
return LoadReturnCode.Success;
}
But it would open duplicates of the panel on load. I think the problem happens because the UI was not fully loaded when OnLoad event is triggered and hence IsPanelVisible could not find the Panel. @menno suggestion worked:
protected override LoadReturnCode OnLoad(ref string errorMessage)
{
// Add an event handler so we know when Rhino has finished loading.
RhinoApp.Idle += OnIdle;
//Register the main view panel
var panel_id = typeof(Views.Panel).GUID;
Panels.RegisterPanel(Instance, typeof(Views.Panel), "MyPanel", Properties.Resources.MyLogo);
return LoadReturnCode.Success;
}
private void OnIdle(object sender, EventArgs e)
{
//Unsubscribe from the event to prevent repeat call to this function
RhinoApp.Idle -= OnIdle;
//Open panel once Rhino has fully loaded.
var panel_id = typeof(Views.Panel).GUID;
if (!Panels.IsPanelVisible(panel_id))
{
Panels.OpenPanel(panel_id);
}
}
Now the panel opens without duplication. The next challenge for me is to figure out how to only do this when the plug-in is first installed…
Any comments welcome! @dale would be great to have the panel launch from the plug-in rather than the command in the Eto examples, it would teach the new devs like me a little bit more about the nuances of how panels interact with the rest of Rhino UI