RobotStudio event

VSTA VB.net example for Visible property

Hello,
  I am trying to use RS 5.12 and VSTA to make a GraphicComponent visible and non visible.  I have been looking at the examples in VSTA but it is not getting me anywhere.  If anyone has done this and doesn't mind sharing their code would you please help out.  Below is what I have thus far and it does not work.

 

Dim PartIndex As Integer = 0
Dim PalletBox As Object
' This method is called when the addin is loaded into RobotStudio.
Public Sub AddInStartup()
' TODO: Add startup code here. Create toolbars, etc.
End Sub
' This method is called when the addin is unloaded from RobotStudio.
Public Sub AddInShutdown()
' TODO: Add cleanup code here. Remove toolbars, etc.
End Sub
' Default sample Macro. Can be removed.
' Note: A Macro is defined as a "Public Sub" method, with
' no arguments and with a name that starts with "Macro_"
' Other methods will not be visible from the Addin Browser.
Public Sub Macro_Sample1()
' TODO: Define actions to perform when the Macro is invoked.
' Logger.AddMessage(New LogMessage("Macro_Sample1 output window message."))
End Sub
Public Sub Macro_ShowPart()
  ' Check that we have an active project
  If Project.ActiveProject Is Nothing Then
   Exit Sub
  End If
  ' Get the currently selected object
  Dim selObject As Object = Project.ActiveProject.Selection.SingleSelectedObject
  If PartIndex = Nothing Then
   PartIndex = 1
  End If
  'selObject = TryCast(PalletBox, GraphicComponent)
  'Define GraphicComponent
  'Select part to Show
  Select_Part()
  ' Create two parts
  Dim GraphicBox As New Part()

  GraphicBox.Name = PalletBox
  Dim gc As GraphicComponent = TryCast(sel, GraphicComponent)
  gc.Name = PalletBox
  'gc = GraphicBox
  'Make the part visible
  gc.Visible =
Not gc.Visible
  PartIndex += 1
End Sub
Public Sub Select_Part()
 Select Case PartIndex
 Case 1
  PalletBox =
"Pallet_1_Box_1"
 Case 2
  PalletBox =
"Pallet_1_Box_3"
 Case 3
  PalletBox =
"Pallet_1_Box_123"
 Case 4
  PalletBox =
"Pallet_1_Box_1_2"
 Case 5
  PalletBox =
"Pallet_1_Box_3_2"
 Case 6
  PalletBox =
"Pallet_1_Box_123_2"
 Case 7
  PalletBox =
"Pallet_1_Box_1_3"
 Case 8
  PalletBox =
"Pallet_1_Box_3_3"
 Case 9
  PalletBox =
"Pallet_1_Box_123_3"
 Case 10
  PalletBox =
"Pallet_1_Box_1_4"
 Case 11
  PalletBox =
"Pallet_1_Box_3_4"
 Case 12
  PalletBox =
"Pallet_1_Box_123_4"
 Case 13
  PalletBox =
"Pallet_1_Box_1_5"
 Case 14
  PalletBox =
"Pallet_1_Box_3_5"
 Case 15
  PalletBox =
"Pallet_1_Box_123_5"
 Case 16
  PalletBox =
"Pallet_1_Box_1_6"
 Case 17
  PalletBox =
"Pallet_1_Box_3_6"
 Case 18
  PalletBox =
"Pallet_1_Box_123_6"
 Case 19
  PalletBox =
"Pallet_1_Box_1_7"
 Case 20
  PalletBox =
"Pallet_1_Box_3_7"
 Case 21
  PalletBox =
"Pallet_1_Box_123_7"
 Case 22
  PalletBox =
"Pallet_1_Box_1_8"
 Case 23
  PalletBox =
"Pallet_1_Box_3_8"
 Case 24
  PalletBox =
"Pallet_1_Box_123_8"
 Case 25
  PalletBox =
"Pallet_1_Box_1_9"
 Case 26
  PalletBox =
"Pallet_1_Box_3_9"
 Case 27
  PalletBox =
"Pallet_1_Box_123_9"
End Select
End Sub



Thanks for the help,
Rick
Rick Lemberg

Comments

  • Hi Rick,
     

    I looked at the code and after a minor modification it works. See code marked with red below. There was no variable named "sel" so I assumed you meant "selObject". To make it more robust to not having selected any objects I added a check on the gc variable. It may also be convenient to add some logging during development, why I added some messages. I suppose you are aware that you can step through your VSTA code and set breakpoints etc. if you press "Run" in VSTA. 

     

     

    Public Sub Macro_ShowPart()

    ' Check that we have an active project


    If Project.ActiveProject Is Nothing Then
    Exit Sub
    End If
    ' Get the currently selected object
    Dim selObject As Object = Project.ActiveProject.Selection.SingleSelectedObject
    If PartIndex = Nothing Then
    PartIndex = 1
    End If
    'selObject = TryCast(PalletBox, GraphicComponent)
    'Define GraphicComponent
    'Select part to Show
    Select_Part()
    ' Create two parts
    Dim GraphicBox As New Part()
    GraphicBox.Name = PalletBox
    Dim gc As GraphicComponent = TryCast(selObject, GraphicComponent)
    If Not gc Is Nothing Then
    Logger.AddMessage(
    New LogMessage("Selected Graphic Component is: " + gc.Name))
    gc.Name = PalletBox
    gc.Visible =
    Not gc.Visible
    Else
    Logger.AddMessage(
    New LogMessage("No Graphic Component selected"))
    End If
    'gc = GraphicBox
    'Make the part visible
    PartIndex += 1
    End Sub
    Henrik Berlin2009-10-01 13:18:05
    Henrik Berlin
    ABB
  • Henrik, Thank you for the help.  However my code was the wrong code.  I am not trying to make a selected object hide but instead select the object with code and then hide or show that object during the runtime of my simulation.  I cannot for the life of me figure out how to do that with VB.net.  Please continue to help.

     

    Thank You,
    Rick Lemberg
  • Never mind, Finally got it figured out:
     

    ' Declare the Station and check for active
    Dim Stn As Station = Project.ActiveProject
    If Stn Is Nothing Then
    Exit Sub
    End If

    If PartIndex = Nothing Then
    PartIndex = 1
    End If
    'Select part to Show
    Select_Part()
    ' Declare GraphicComponent and then assign it
    Dim gc As GraphicComponent = Stn.GraphicComponents(PalletBox)

    'Make the part visible
    If gc IsNot Nothing Then
    gc.Visible =
    Not gc.Visible
    PartIndex += 1
    gc =
    Nothing
    Else
    Logger.AddMessage(
    New LogMessage("Selected Object: This is not really an object" + gc.Name))
    End If



    Thank You for the help earlier,
    Rick
    Rick Lemberg