ghpython execute in steps

ghpython execute in steps

A very simple example to illustrate a basic code structure to create iterative algorithmic sketches with ghpython in combination to the usual components within Rhino Grasshopper (GH).

The basic idea is to mimick the way Processing and Unity structure the code in two sections 1. Setup – initial configuration (processing: setup() & unity: Start()) 2. Draw – Code that repeats (processing: draw() & Unity: Update()). A third section is added which could be attached to “setup” or “draw (loop)” to visualise the initial configuration or the current state of the system coorespondingly (remove the link between makeDirty – dirty for the former (Note: “dirty” is a term from Maya hypergraph when a node further up the graph trigger changes to a node further down the graph, I believe the GH community calls it “expires”). this link forces GH to execute the middle block first given the way the GH graph is structured).

The setup block contains a python node with a python object. The outputs are instances of the object (either as one instance or multiple instances in a list as in the example). Changes made to these instances are retained (e.g. position and vector in the example) for the next iteration – this makes it possible to record information while we execute part of the GH graph.

To run the “draw (loop)” block either induce a change by changing one of its inputs (for example a button connected to “run”) or use the GH timer component to trigger the first node within the block repeating at a defined time interval.

GH file with python code:
pycheung.com/temp/python_execBySteps_template.zip

Leave a Reply

Your email address will not be published. Required fields are marked *