hello
i have 2 questions.
first , is there unique id on product? if there is , where is it? can i use it on script?
example 1, Boxes from same feeder , but i think there are unique id like Box#1 , Box#2 , Box#3...
Sec , if there is unique id on product , or Component i want to look up Product states.
especially , i want to know where the product is now… like on store , conveyor , robot , etc
how can i inquiry it on script?
example 2,
product name / ID / Location / etc.
box / #1 / store /
box / #2 / conveyor_3/
box / #3 / Robot_5 /
need help!
Feeder-created component is dynamic component, so we can use OnDynamicComponent event to track, here is an simple example, I use creation time as ID, but you can develop your own style.
Drag and drop the attached component, click Check button while running the simulation, you will see the info.
DynamicComponentInfo.vcmx (39.9 KB)
from vcScript import *
from datetime import *
sim = getSimulation()
# When simulation start
def OnStart():
# Make component_dict as global variable
global component_dict
# When simulation start, clear dict
component_dict = {}
# When dynamic component is created or removed
def OnCreated(component, container, added):
if added:
if component.Name not in component_dict:
component_dict[component.Name] = []
component_dict[component.Name].append(component)
else:
component_dict[component.Name].remove(component)
# Get application instnace
app = getApplication()
# Feeder-created component is dynamic component
# Add event to record
app.OnDynamicComponent = OnCreated
# Get self component instance
comp = getComponent()
# WHen button check is clicked
def OnCheck(arg):
print "-"* 30, datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), "-"* 30
# Sort dict keys by component name
component_keys = component_dict.keys()
component_keys.sort()
for component_key in component_keys:
print component_key
for component in component_dict[component_key]:
# Current component world matrix
vector = component.WorldPositionMatrix.P
# Print info
print "\t%f: %s, %s (%f, %f, %f)" % (round(component.CreationTime, 3), component.Container.Name, component.Container.Component.Name,
round(vector.X, 2), round(vector.Y, 2), round(vector.Z, 2))
# Get property instance
check = comp.getProperty("Check")
# Add button-clicked event
check.OnChanged = OnCheck
thanks a lot ! im gonna try this!