Accessing and working with User Control Panels


#1

Hi everyone,

I just created my first UserControl Panel. I put some buttons, a field and labels on them.
The labels should display certain values of the current model (Angle Tol, Unit System, etc.)
The field should display user Strings of an Object
The Buttons basically should run Commands

HERE ARE MY QUESTIONS:

  • Accessing the User Control from a Command
    In Order to change something on the User Control, e.g. a label, I need to access it. But how do I do that? Could someone provide a snippet on how to change the text of a Label on a User Control from a Rhino Command.

  • The Properties Window in Rhino changes its contents depending on if and what is selected in the viewports. How does that work. How could I display e.G. User Strings of a selected object?

Thanks in advance for your Help
Karl


(Dale Fugier) #2

Have you seen this sample?

https://github.com/dalefugier/SampleCsPanel


#3

Hi Dale,

thank you for the post. It really was helpful to see how you set set it up.

Currently, I have the same functionality you have in your Example. (Register, Show and Hide the UserControl Panel)
However, the question I have is more of what comes after I have it set up.

I’m stuck at the part, where I want to acces the User Control.
Here is what I tried - but it didn’t work.

override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Get the User Control ID
            System.Guid panelId = UI.MainUserControl.PanelId;

            //Check if the panel is already opend, if not, open it
            bool panelVisible = Rhino.UI.Panels.IsPanelVisible(panelId);
            if (!panelVisible)
            {
                Rhino.UI.Panels.OpenPanel(panelId);
            }
            
            MainUserControl panel = (MainUserControl)Rhino.UI.Panels.GetPanel(panelId);
        panel.Label1.Text = doc.ModelAbsoluteTolerance.ToString();

Do you undestand my problem? (It’s hard for me to explain)

Thanks
Karl


(Dale Fugier) #4

Look here:

https://github.com/dalefugier/SampleCsPanel/blob/master/SampleCsPanelUserControl.cs

Notice how the constructor is adding a reference to itself the the plug-in object?