Panels.GetPanel(Guid id) doesn' work

Hi,

The method Panels.GetPanel(Guid id) seems to be not working, it always return a null object even if you get panelId from Panels.GetOpenPanelIds();

Tested in RhinoApp.Initialized method.

Thanks.

http://mcneel.myjetbrains.com/youtrack/issue/RH-29595

Panels.GetPanel only returns panels created with RhinoCommon. If a panel were created with the Rhino C++ SDK, Panels.GetPanel will return null.

Does this help?

Hi Dale,

Thanks but I used .NET (it’s a Rhino C# plugin in fact) I have all panel ids (Rhino panels and plugin panels) but I’m not able to get any panel through Panels.GetPanel(Guid id) in c#, is there any other way to access to a panel by it’s id?

Thanks

You might want to review the following RhinoCommon sample:

https://github.com/dalefugier/SampleCsPanel

If you look in the constructor of the user control, you will see that it sets itself as a reference on the plug-in object. This way, you can get to the user control from anywhere, like a command for example. I’m assuming this is why you want to get to your panel…

Hi Dale,

Thanks, I could do that with my panels, but I have no way to access to Rhino panels, so the only way is through Panels.GetPanel(Guid id) and it doesn’t work even giving it a Rhino panel Id.

Is there an other way to access to Rhino Panels? (I mean the UserControl object)

Thanks.

Rhino panels are not written .NET. So there is no UserControl to get. Why do you need to get a hold of Rhino panels?

Hi Dale,

I need to store the latest opened panel, to make it active in some situations.

So I tried to iterate the panels in OnShutdown() method like this

Guid lastPanelOpen = Guid.Empty;

        var panels = Panels.GetOpenPanelIds();
        foreach (var id in panels)
        {
            if (Panels.IsPanelVisible(id))
            {
                lastPanelOpen = id;
                break;
            }
        }

But it always return an empty Guid list, so I thought I could get the panel objects (inherit from UserControl in .NET) in RhinoApp.Initialized, and register the OnFocus() event to store it’s id in a global variable when panel get the focus, and have access to the last open panel once Rhino is closing.

So do you know any way to do that?

Thanks!

So… then is it a bug? is there any way to access to the panels?

Thank you.

Why? Help me understand why you need to do this? Doesn’t Rhino already do this?

RhinoCommon (.NET) cannot access panels created in C++.

I’m still trying to understand what you need and why…

Hi Dale,

At start of my plugin (RhinoApp.Initialized) I register my panels and I open them as sibling of rhino panels like this:

Panels.RegisterPanel(ThePlugin, typeof (MyPanel1), Localize.Panel1Caption, Resources.MyIcon1);
Panels.OpenPanelAsSibling(MyPanel1.Id, PanelIds.Layers);

Panels.RegisterPanel(ThePlugin, typeof (MyPanel2), Localize.Panel2Caption, Resources.MyIcon2);
Panels.OpenPanelAsSibling(MyPanel2.Id, PanelIds.Layers);

Panels.RegisterPanel(ThePlugin, typeof (MyPanel3), Localize.Panel3Caption, Resources.MyIcon3);
Panels.OpenPanelAsSibling(MyPanel3.Id, PanelIds.Layers);

But MyPanel3 in this case is always the active one, so by this reason I want to store which was the active one (when Rhino is closing) to restore it after register and open my panels.

Thank you.

Keep in mind that Rhino panels can be dragged into any docking container. So while your panels may start out in the same docking container, the user might drag them into another container. Or they may drag another panel into the docking container that contains your panels.

Also, Rhino maintains the visibility and location of all panels. Then Rhino restarts, it automatically loads any panel that was open when Rhino closed, and puts it back in the same location. Thus, your plug-in does not need to open panels when it loads (as Rhino will do this for you).

That said, if it is important for you to manage your panels in a different way, you might want to consider creating just a single panel and have a user control with a TabControl. Thus, instead of juggling 3 Rhino panels, you only need to deal with one.

Thanks Dale,

That’s right but anyway every time the panel is opened “AsSibling” the last panel opened is the active one.

For instance when Rhino is closed the last panel opened in one of the dock containers is Rhino Properties Panel, in Load plugin I open the custom panels as sibling and the last panel which is opened is still the active one instead the Rhino properties panel.

The problem is, if I add some panel, this panel will be the focused panel.

Regards.

It sounds like we need to add a function that will allow you to set the active panel tab, correct?

It would be great!, and if you could fix the function to get the active panel at shutdown it will help a lot.

Thanks Dale.

Try this: after registering and opening all of your panels, re-open the panel you want to have focus. Does this help?

Panels.OpenPanel(focus_guid);

Hi Dale,

Yes that’s the point, but I would need to store the (focus_guid panel) at shutdown time, to restore it at stratup time with Panels.OpenPanel(focus_guid); that’s the main problem.

Regards

You could save your focus_guid somewhere in the VisibleChanged for your control. Meaning you track this essentially all the time, and not wait for the shutdown. If your control is visible → save. If it is not visible → remove.

/Nathan

I can do that with my panels (windows form controls) but I’m not able to get this information for Rhino panels.

Hello Dale,

There are some news about that?

Thanks and regards.

Sorry, I am unclear to what problem you are trying to solve. If you want to a Tab to have focus, just call Panels.OpenPanel.