RobotStudio event

How to write event handler in VB?

Options
My VB add-in needs to detect when a new selection is made in the graphics window.

I think I have to link my subroutine to to the GraphicPicker.GraphicPick event, but cannot work out how to do this from the API Help.

Would somebody please give me some example code.

Thanks,

Kevin

Comments

  • Henrik Berlin
    Options
    The following topic discusses event handling in C#. Perhaps that can give some guidance.
     

    Henrik Berlin
    ABB
  • Henrik Berlin
    Options

    ... btw ... It think this is the event to use

    Public Event SelectionChanged As EventHandler
    Henrik Berlin
    ABB
  • Kevin
    Options
    Thanks for your reply Henrik,

    The API Help shows 'SelectionChanged' associated only with 'ToolControlBase', 'CommandBarComboBox' and 'ReferenceComboBox' but states that the 'GraphicPicker.GraphicPick' event ... "occurs when the user picks an object in a graphic view", which I think is what I want.

    I have converted the C# example from your link to VB, but after much experimenting I still have not managed to write a working handler and link it to my required event.

    I would be very grateful if someone would give a detailed example of how to do this in VB.

    Thanks,

    Kevin



  • Kevin
    Options
    OK, I sorted it. For the benefit of anyone else who is struggling with event handlers in VB, here is an example which displays a message box whenever a face or body are selected.

    Add a reference to 'ABB.Robotics.RobotStudio.Stations.Forms' in the form or module properties then include this line at the start of the form/module code:
    [CODE]Imports ABB.Robotics.RobotStudio.Stations.Forms[/CODE]
    Add this code so that it executes before a graphic selection will be made:
    [CODE]AddHandler GraphicPicker.GraphicPick, AddressOf MySub_SelectionChanged[/CODE]
    Then add the handler subroutine:
    [CODE]    Public Sub MySub_SelectionChanged(ByVal sender As Object, ByVal e As GraphicPickEventArgs)
            If e.PickedObject IsNot Nothing Then
                If e.PickedObject.TypeDisplayName = "Face" Then
                    MsgBox("Face selected")
                ElseIf e.PickedObject.TypeDisplayName = "Body" Then
                    MsgBox("Body selected")
                End If
            End If
        End Sub
    [/CODE]

    Kevin