Rhino.UI.Panels.GetPanel<T>() returns null

I have a plugin with a docking panel to show user data when opening a .3dm file. The docking panel is registered in plugin.OnLoad and opened/shown using a command. Everything works fine. However, Rhino.UI.Panels.GetPanel always returns null when plugin.ReadDocument is being called. Rhino.UI.Panels.GetOpenPanelIds shows the docking panel is indeed in the list. I also try it in Rhino.RhinoDoc.EndOpenDocument and Rhino.RhinoDoc.EndOpenDocumentInitialViewUpdate, all returns null.

Is this intended behavior? a bug? Or how do I get the docking panel while its contents are populated during plugin.ReadDocument?

@dale can you help?

Thanks!

You can register the panel with PanelType.PerDoc and add a public constructor that accepts a RhinoDoc as argument to it, then it will be called by rhino once a document is read.

Hi Marco,

Tried both PanelType.PerDoc and PanelType>System but could not get it to work.

My issue is not to get the panel’s constructor called and do something therein when a document is read. The panel has a treeview and some tree nodes need to access the panel when they are instantiated while a document is being read. Calls to Rhino.UI.Panels.GetPanel() inside those tree node constructors return null.

Hope that clarifies.

V/r,

Jun

Hi @Jun_Li,

I don’t understand why are are calling Panels.GetPanel. What are you expecting this to do for you?

– Dale

Hi @dale,

The docking panel has a TreeView and some tree nodes have to listen to events like AfterSelect. Since TreeNode does not handle these kinds of events directly but via its container TreeView, it needs to register to TreeView’s event handlers during instantiation. That’s why inside custom TreeNode constructor, a reference to the docking panel has to be obtained. All such tree nodes are being instantiated during a call in Plugin.ReadDocument and I thought Panels.GetPanel would do that, but it returns null. I believe (could be wrong) there are good reasons that prevent from access of the docking panel while a document is being loaded, especially it registers with PanelType.PerDoc.

Anyway, I found a way to get it work using PanelType.System and many nuances in handling it here and there.

V/r,

Jun