Hi everyone,
I am trying to build a simple custom vacuum gripper using a cylinder, a RaycastSensor, and a Python Script.
My goal is to grab a part when a Boolean Signal (“Grasp Signal”) is set to True.
My Component Structure:
- Zylinder 6 (Root)
- Behaviors
- PythonScript
- Grasp Signal (Boolean)
- RaycastSensor
- Behaviors
I have connected the signal to the script, but I keep running into API issues regarding the RaycastSensor attributes.
Here is my code:
from vcScript import *
def OnSignal(signal):
if signal.Name == “Grasp Signal”:
if signal.Value == True:
grab()
else:
release()
def grab():
comp = getComponent()
sensor = comp.findBehaviour(“RaycastSensor”)
if not sensor:
print(“Error: Sensor not found”)
return
THIS IS WHERE IT FAILS:
I tried accessing the detected part, but I get errors.
try:
part = sensor.TriggeredComponent
if part:
comp.attach(part)
print("Attached: " + part.Name)
except:
print(“Error accessing TriggeredComponent”)
def release():
comp = getComponent()
for child in comp.ChildComponents:
comp.detach(child)
The Error Message:
When I trigger the signal manually, the Output panel shows:
“NameError: Attribute or method ‘TriggeredComponent’ not found.”
I also tried accessing sensor.Signal or sensor.Component, but I get similar “Attribute not found” errors.
The RaycastSensor itself is found by findBehaviour, but I cannot access the detected object.
Does anyone know the correct API attribute to get the detected part from a RaycastSensor in my version?
Any help is appreciated!
Versuch 5 if.vcmx (277.0 KB)