Hello,
I am interesting in using Python to hide and show components in VC. Also moving components etc.
Any assistance will be greatly appreciated.
John
Hello,
I am interesting in using Python to hide and show components in VC. Also moving components etc.
Any assistance will be greatly appreciated.
John
Here is a tutorial
vcNode.Visible - affects visibility of node and its child nodes
vcNodeVisible - affects visibility of node but not its child nodes
Thanks Zesty!
Worked a treat and now getting into some Python scripting.
Regards,
John
I have managed to get a component moving using the following code
def OnRun():
comp = getComponent()
servo = comp.findBehaviour(‘Servo Controller’)
servo.setJointTarget(2,0)
servo.move()
I am also able to hide and show it using signals
mypart= app.findComponent(“JPB_PART”)
def OnSignal( signal ):
if signal.Name == “MyPartSignal”:
if signal.Value:
mypart.Visible = True
else:
mypart.Visible = False
Could anyone help with setting signal values with python code?
i.e. set signal 201 to true
and how to do a wait until signal 201 equals true
I’m also able to call a subprogram to execute on a robot using
robot = app.findComponent(‘GenericRobot’)
rx = robot.findBehaviour(“Executor”)
#disable executor from automatically running its program
rx.IsEnabled = False
rx.callRoutine(rx.Program.Routines[0])
I would like to use signals to help control part movement between robot programs.
Any assistance is greatly appreciated.
Many thanks,
John
You could use vcExecutor.DigitalInputSignals.input() to get the signal value and verify that in either a condition or event handler
condition(lambda: rx.DigitalInputSignals.input(201) == True)
Likewise, vcExecutor.DigitalOutputSignals.output(201, True) to set the value. This, of course, is assuming port/signal 201 is wired as both an input and output of robot.
Set a boolean signal
output = comp.findBehaviour('OutputSignal')
if not output:
output = comp.createBehaviour(VC_BOOLEANSIGNAL, 'OutputSignal')
output.signal(True) # or False depending on the Value you want to set
Please keep in mind that there is also a possibility to read and write the Value of a signal with “output.Value”, but this won’t trigger anything to recognize that the value has changed e.g. OnSignal if the signal is connected to another components python script.
Waiting for a boolean signal
There are multiple ways how you can wait for a boolean signal.
triggerCondition(lambda: getTrigger() == input and input.Value == True)
condition(lambda: input and input.Value == True)
I’ve attached a sample layout for you where all those methods are shown.
Edit: Unfortunately I have missed the point that you want to set a certain signal of a booleansignalmap, but zesty covered this already.
SampleLayout.vcmx (29.4 KB)
Thanks Felix and Zesty,
I managed to get this to do what I wanted to do. I would still like to remove the robot and somehow program the XYZ device and be able to connect the signals to it. This would make it an independent device that I could reuse again.
Please find my model for those interested in doing this in the future.
Regards,
John