I am using ghenv.LocalScope.TryGetVariable(). This worked fine in rhino7 grasshopper, but when I switched to rhino8 grasshopper python3, it gives me error.
@Yiran Would you mind sharing an example script? Why not just use setup_done inside the script? If that is an input parameter on the component it will be available in the script scope.
I am trying to understand what the use case is for accessing ghenv.LocalScope. In Python 3, the scope is very different that python 2 so I have removed this property from ghenv. I can bring it back if there is a specific use case
I am trying to use MQTT inside Grasshopper. I use trigger to call this component, and I only want to create one MQTT client at the beginning. In my script, setup_done is defined later, so I used TryGetVariable.
Here is part of my script:
is_setup_done = ghenv.LocalScope.TryGetVariable("setup_done")
if setup and not (is_setup_done[0] and is_setup_done[1]):
try:
# reinitialise client
print("Client reinitialized")
except:
# create client
print("Creating new client")
# connect client and set up callback function
setup_done = True
print("Starting")
elif setup:
pass
elif is_setup_done[0] and is_setup_done[1]:
# disconnect client
setup_done = False
print("Client disconnected")