Scriptcontext.sticky on Mac problem

Hi @Pascal,

i’m not sure if i’m missing something but i cannot get the scriptcontext.sticky to work under Mac using version 7.9. To repeat what i see, please run _EditPythonScript and type the following into the editor:

import scriptcontext
scriptcontext.sticky["Hello"] = "World"

please run this script, then change the second line to this:

print scriptcontext.sticky["Hello"]

once started, i get this result:

Exception Occured, Message: Hello

if i query the sticky dictionary like this:

print scriptcontext.sticky.has_key("Hello")

it returns False.

???

_
c.

When you save two files, one mapping a sticky key to some value and the other trying to get the value from sticky, and run them one after the other, it works fine!
Weird right?

test_a.py :

import scriptcontext as sc

sc.sticky["foo"] = "bar"

test_b.py :

import scriptcontext as sc

print sc.sticky["foo"]

Maybe it has something to do with the Python editor storing TempScript.py in
/var/folders/dq/n7fdtfps47s3c21pbw7ybl100000gn/T? I have no clue. :slight_smile:

Hi @diff-arch, yes weird and thanks for testing it. It seems the sticky dictionary has Alzheimer on Mac. I stumbled over this bug actually with a single script file saved on disc which is started from a panel button using:

! _-RunPythonScript ScriptName.py

I have set a global searchpath for all scripts in the EditPythonScript Options to omit the path. Does below code work on your side if you save it to disc and run it from a button ?

import scriptcontext

def DoSomething():
    
    key = "Hello World"
    if scriptcontext.sticky.has_key(key):
        print "The key '{}' was found in sticky".format(key)
    else:
        print "Not found, adding key '{}' to sticky".format(key)
        scriptcontext.sticky[key] = "OK"

DoSomething()

thanks,
c.

I’ve run it as a macro to test it. And it seems to work.

Screenshot 2021-11-03 at 21.22.48

Sorry, for not testing it with a button, but on macOS, it is a horrible, horrible, horrible, horrible, horrible, horrible, horrible, horrible workflow to create one.

:wink: i agree. In my work i need to frequently update a panel and send the whole workspace to a client.

If i run above from a button, scriptcontext.sticky does not seem to remember that the key was added on the second run. I hope that someone can confirm and fix this.

_
c.

Hi @clement,

sticky is just a dict.

rhinoscriptsyntax/scriptcontext.py at rhino-7.x · mcneel/rhinoscriptsyntax · GitHub

You can also hang stuff of the document’s runtime data table.

RhinoDoc.RuntimeData Property

– Dale

Hi @dale,

i can use the scriptcontext.sticky dictionary on Windows and set key, value pairs when i run the script once. On a second run (with the same document) it remembers what i set at the first run. On Mac OS, this does not seem to work.

the code in your link states this in the comment:

A dictionary of values that can be reused between execution of scripts

But i cannot reuse the dictionary on MacOS.

Unfortunately, i have many scripts which use scriptcontext sticky and i have never had a problem on Windows. Can you repeat my problem on MacOS ?

_
c.

Since nobody else has taken pity, I’ve run some tests like requested above.

The screen capture was taken with the script residing in “/Users/<username>/Library/Application Support/McNeel/Rhinoceros/7.0/scripts”, for which I defined the macro ! _-RunPythonScript clement.py.
This works because scripts is the default Rhino script folder that is auto-loaded, meaning you can put Python scripts there and import them in the Rhino Python editor or a GHPython component and they will load, without having to do any other trickery.

I’ve done another test with the script placed on my desktop, and this also ran fine!
In this case, I just had to change de macro path to an absolute one, resulting in this command:
!_-RunPythonScript "/Users/<username>/Desktop/clement.py".

Yes, it does. It just seems that it’s just the Rhino Python editor that fails make sticky items well stick. In GHPython and macros, it works fine!

Let me know, if you want me to test anything else.

1 Like

Hi @diff-arch, thank you very much for your thorough test!

I’ll try to find out why it works on your side but not on mine. My asumption is that the button i use to invoke the script is inside an Eto Form which remains open all time during scriptrun.

_
c.