Hey,
I’m new to VC but I would like to thank your courses and lessons that are very clear even for people like me where english is not native language.
I’m able to simulate a conveyor that feed different kind of boxes but I kept changing the box’s height in order to check if my robot do the job the way I wanted.
Is there a way with python script to randomly modify box’s height into the conveyor , then to simulate it and the conveyor send box with different height.
Hope you’ll be able to understand what I’m saying.
thx in advance
With python’s random module you can randomly set a real parameter. So let’s say you have a conveyor component which has a path called “Path__HIDE__”. Then you feed block parts on the conveyor which have a real parameter “Height_Z” to set the height of the block. Now you could create a python script in the conveyor and use the snippet below to set that height to a random value between 200 and 400 mm when part enters the conveyor.
from vcScript import *
import random
comp = getComponent()
path = comp.getBehaviour('Path__HIDE__')
def part_transition(part, arrive):
if not arrive:
return
prop = part.getProperty('Height_Z')
if not prop:
return
prop.Value = random.uniform(200, 400)
path.OnTransition = part_transition
Here’s an example model (app version 4.2): Random_block.vcmx (180.4 KB)
I’ve an example with creating randomized cylinders, which are in a component.
The “Cylinder” feature is changed after creation randomly and then it’s updated.
Setting properties on a feature (Height, Radius, etc.) requires str as far I know. They are expressions.
The second part is the detection of these properties on the “Cylinder” feature. CreatorRandomCylinder.vcmx (194.3 KB)
PS: Using path-sensors, require that the frame is also on the Path itself. If you forget this, the sensor does not detect anything. A better approach could be the use of the ProcessModel. But I haven’t used it yet.
Others have given examples that answer your question. If it is for debug or testing purposes, consider using Advanced feeder or library like Works to create boxes with different heights that are fed to conveyor as alternative to scripting.
I made a test layout in which the box changes its height when it is created during simulation. I do not recommend this approach for various reasons.
It is just an experiment to test certain things such as feature sharing, feature tree evaluation, performance, expression calculation, troubleshooting primitive feature expression versus Transform scaling expression, part vs component creator, etc. I did not go so far with the layout to test with Python Feature since it is rarely used in component modeling, albeit as an alternative for Transform feature.
The examples of keke and deadeye use the random module in Python 2.7 to get a pseudo-random number. In keke’s example, keke uses a component property (parameter) to control the height, which is a real number. In deadeye’s example, deadeye uses expression, which is a string, to set a default property of a Cylinder feature. The expression is calculated to return a value (the calculated value).