Process Feeder Controlled by Boolean Signal

I want to trigger a new product with a Boolean signal from a robot or push button.
I wrote the code below, it does everything but create a part.

from vcScript import *

Find the Product Creator and Boolean Signal behaviors

comp = getComponent()
pcreator = comp.findBehaviour(“ProductCreator”)
signal = comp.findBehaviour(“CreateProduct”)

def OnRun():
“”"
Executed when the simulation is started or reset.
Sets the creator’s limit to 0 to disable internal logic.
“”"
print(“nope”)
pcreator.SingleFeed.Limit = 0
pcreator.SingleFeed.Interval = 0

def OnSignal(signal):
“”"
Executed when a connected signal changes value.
“”"
if signal.Name == “CreateProduct” and signal.Value == True:
# Set the limit to 1 to create a single product
print(“Yup”)
pcreator.SingleFeed.Limit = 1
pcreator.SingleFeed.Interval = 1

# Wait for the creator to produce the item
# Note: In version 4.10, you can use creator.create() for Component Creators, 
# but with Product Creators, setting the limit is the standard approach.

# Reset the limit and signal after the product has been created
# Delay this action slightly to ensure the product has time to be created.
delay(2)
#pcreator.SingleFeed.Limit = 0
signal.Value = False

For custom product instance creation from scripts you can just create them directly from vcProductType. No need for a product creator behavior at all.

1 Like

Hello @TSy , do you have more info on how to use this vcProductType? I am trying to create differant products based ona custom logic and signal from a downstream process.

Thanks!

Have a look at the script from the component Signal Feeder

Otherwise ypu can try without Python script: Python Script Begineer_Component Creation - #3 by Tilma