Initiate variable in GH file's scope in GhPython component

Is there a way to start a variable, say a list “L0” in the GH file scope so it is there whenever I want to access it and from whichever GhPython component? I’ve used the global keyword and it seems to be within each GhPython.

The long version is that I have a Ghpython component that has a few boolean inputs. The first is for picking objects in rhino to set up an initial list. Another boolean will add to the list and a third will remove objects from it. At any given point, if the first boolean is true again, the list reset to whatever is newly picked.

You can store stuff in any loaded module. An example would be an entry in the sticky dictionary.

I hope this helps,



Giulio Piacentino
for Robert McNeel & Associates

Yep that’s it.

If I have multiple GhPy components that do things to the same value in sticky, how is priority determined?

I had a conversation about this with @DavidRutten. He does not want to commit to certainty, but basically the last-drawn component is also the last-solved component, if they are unattached. If they are attached, there are some internal rules subject to change.

Thank you.

So, if I create one scripting component (before putting anything else on the canvas). If I use this first script to just define global stickies, will it work as if I have defined them outside the runscript() for each component??

If you refer to scriptcontext.sticky, there’s no difference in where you define it from. First comes first.
If you have more questions, please start new threads.