Accessing panel elements from command class

Hi All…

I’m having trouble accessing label elements on a panel from inside a command class. Below is the code I have and it works and displays the panel. The panel has label elements IE: lblXInfo and lblYInfo. I need to update those based on data retrieved during the initialization process inside initEncoders(). How would I go about this? Thanks

    Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result
        Dim panelId As Guid = pnlEncData.PanelId
        Dim bVisible As Boolean = Panels.IsPanelVisible(panelId)

        Dim go As New GetOption()
        Dim hide_index As Integer = go.AddOption("Hide")
        Dim show_index As Integer = go.AddOption("Show")

        go.[Get]()
        If go.CommandResult() <> Result.Success Then
            Return go.CommandResult()
        End If

        Dim [option] As CommandLineOption = go.[Option]()
        If [option] Is Nothing Then
            Return Result.Failure
        End If

        Dim index As Integer = [option].Index
        Dim mPanel As Panels = Panels.GetPanel(panelId)

        If index = hide_index Then
            If bVisible Then
                Panels.ClosePanel(panelId)
                closeEncoders()
            End If
        ElseIf index = show_index Then
            If Not bVisible Then
                Panels.OpenPanel(panelId)
                initEncoders(panelId)
            End If
        End If

        Return Result.Success
    End Function

Along the same lines, if I move the init and close code over to the plugin class, how would I call those functions from the command class? I got all of this working in a separate windows form app, but can’t seem to get it going when I transfer it over to the plugin.

Thanks

So I was able to get it to compile by creating an instance of the plugin class where the functions exist, but it doesn’t run. I’m guessing that’s because there can only be one instance of the plugin class. So the I figure the answer is to get a reference to the class that is already there. How would one go about that?

  Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result
        Dim panelId As Guid = pnlEncData.PanelId
        Dim bVisible As Boolean = Panels.IsPanelVisible(panelId)
        Dim go As New GetOption()
        Dim hide_index As Integer = go.AddOption("Hide")
        Dim show_index As Integer = go.AddOption("Show")

        Dim tc As New TrucutTracer() 'This is the plugin class

        go.[Get]()
        If go.CommandResult() <> Result.Success Then
            Return go.CommandResult()
        End If

        Dim [option] As CommandLineOption = go.[Option]()
        If [option] Is Nothing Then
            Return Result.Failure
        End If

        Dim index As Integer = [option].Index

        If index = hide_index Then
            If bVisible Then
                Panels.ClosePanel(panelId)
                tc.closeEncoders()
            End If
        ElseIf index = show_index Then
            If Not bVisible Then
                Panels.OpenPanel(panelId)
                tc.initEncoders()
            End If
        End If

        Return Result.Success
    End Function

Hi Ross,

I’ve tuned up my VB Panel example to show you how to store a reference to your user control on your plug-in object. This way, you can always get to the user control from anyware via the plug-in object.

@dale Sorry for digging in old stuff but does it relates to v6? I have issue when i want to hook to panel control and pass observable collection during new/open document event.

What is the issue?

– Dale

@dale i have observable collection which i have to hook to ui as soon as new/open doc event fires but in v6 it seems that panel is not created yet so i hooked to ui after winform host init what is some kind of workaround - so far is working. In v5 even if panel wasn’t selected and viewed i could hook to this panel. Which actualy means that ui class in v6 don’t return itself from static method like in your example so it isn’t accessible as long as it isn’t initialized by user by viewing panel.

D-W,

The panel systems work differently in V5 and V6.

V5 Windows behavior:

  • The registered panel class must be a public class and contain a default constructor that takes no parameters.
  • A panel object is created one time when it is referenced by a visible host container and will survive for the length of a Rhino session.
  • When a panel is moved to a different host container the panel objects parent is changed to the new host and the same panel object is used.

V6 Windows behavior for per document panels:

  • The registered panel class must be a public class and registered as a PanelType.PerDoc panel (the default PanelType).
  • Rhino looks for public constructors in the following order:
    • Constructor taking a RhinoDoc
    • Constructor taking a uint representing the documents runtime serial number
    • Constructor with no arguments
  • A panel object is created for each time a new document is created if the panel is in a visible host container and disposed of when the document closes.
  • When a panel is moved to a different host container the panel objects parent is changed to the new host and the same panel object is used.

V6 Windows behavior for system panels:

  • The registered panel class must be a public class and registered as a PanelType.System panel.
  • Rhino looks for public constructors in the following order:
    • Constructor taking a RhinoDoc
    • Constructor taking a uint representing the documents runtime serial number
    • Constructor with no arguments
  • A panel object is created one time when it is referenced by a visible host container and will survive for the length of a Rhino session.
  • When a panel is moved to a different host container the panel objects parent is changed to the new host and the same panel object is used.

Mac Rhino 6 works the same as Windows with the exception that there may be more than one panel instance per document.

Note: Rhino 6 includes a IPanel interface which can be implemented to determine when a panel is shown, hidden or closed.

All of that being said, static methods on RhinoDoc should be hooked by your panel class when created and unhooked when dispose of in both V5 and V6.

2 Likes