Global constants

I have a large Grasshopper program with many Python code blocks.

Is it possible to define global scope constants accessible to all Python code blocks?

Put them in the sticky dictionary (that can be accessed across all GHPython components and the Rhino Python editor within the same Rhino instance).

1 Like

Thank you!

I tried to use this approach to prevent my Grasshoper file looking spaghetti from wiring the same variables all around. When I change one of those variables, this doesn’t update the “output” script:
Screen Shot 2022-11-03 at 3.31.50 PM which is very unfortunate.

The issue there Gui is that there is nothing to tell the other component that it has expired.

You will need to do that manually in the first component. It is probably easier to use ‘ghenv.Component.blah’ in the second component to get some ID information to hard code into the first.

If you ask me, wires are good. They indicate a connection in between components, and they define a strict order of computation. What you probably don’t want is a wire for each parameter. In order to prevent that issue, just put variables in a single anonymous type, such as a tuple, and pass them in one go from one component to another.

2 Likes