My goal is to have a script that will insert a command after the selected instruction in a program. The snippet of code below finds the instruction that is selected/highlighted. It is a robodk.robolink.Item object. Next, the script looks at the parent of this (which should be an ITEM_TYPE_PROGRAM) and loops through the instructions looking for a match.
However, using program.Instruction(n) returns a tuple. So, I have a tuple and a robodk.robolink.Item with no way to check if they are the same. I cannot use the Item.Type() + Item.Name() because the names are not unique.
I hope that I explained that so it made sense...
This code is part of a PySide app - sorry if it looks a little different.
However, using program.Instruction(n) returns a tuple. So, I have a tuple and a robodk.robolink.Item with no way to check if they are the same. I cannot use the Item.Type() + Item.Name() because the names are not unique.
I hope that I explained that so it made sense...
This code is part of a PySide app - sorry if it looks a little different.
Code:
def btnSelectedItem_Clicked(self):
'''Show information about the selected item in the tree'''
self.ui.textInfo.clear()
currentSelection = self.rdk.Selection()
if len(currentSelection) == 0:
self.ui.textInfo.append('No items selected')
return
item = currentSelection[0]
itemType = item.Type()
itemName = item.Name()
itemParent = item.Parent()
itemVisible = item.Visible()
self.ui.textInfo.append(f'{itemName=}')
self.ui.textInfo.append(f'{itemType=}')
self.ui.textInfo.append(f'{itemParent=}')
self.ui.textInfo.append(f'{itemVisible=}')
self.ui.textInfo.append(f'type={type(item)}')
# The parent is a program, so it must be an instruction
if itemParent.Type() == 8:
instructionCount = itemParent.InstructionCount()
self.ui.textInfo.append(f'Looping through {instructionCount} instructions...')
for n in range(instructionCount):
self.ui.textInfo.append(f'Instruction {n}')
current = itemParent.Instruction(n)
# How to compare if item == current?
# current is a tuple and item is an robodk.robolink.Item

