I have a Python script which does some stuff and remembers which state it is in after doing the stuff. I then use scriptcontext.sticky to remember what state the file is in.
The problem is if I undo the changes then Rhino doesn’t undo the change in scriptcontext.sticky, so it thinks it is in the new state when it is really back in the old state.
Is there a way to undo changes to scriptcontext or another undoable way to remember variables in a Python script? sample script:
import scriptcontext as sc
import rhinoscriptsyntax as rs
def statechange():
if sc.sticky.has_key("state"):
state = sc.sticky["state"]
else:
state = False
rs.MessageBox("changed state to "+ str(state))
rs.AddPoint(0,0,0)
state = not state
sc.sticky["state"] = state
if __name__ == "__main__":
statechange()
I don’t think so, not without a lot of other complications… Even normal Rhino commands that store command-line choices within a session will not undo the current choices and go back to the previous ones if you undo the operation… Sticky is just a place where where you can store and retrieve stuff within a session.
If you really need to be able to undo the sticky settings, I surmise that you will need to keep a whole undo stack stored somewhere - maybe also in sticky, but could also be stored in the document - then you will need to use a special “Undo” that will look at your stored undo stack and restore the previously used settings…
Thanks / merci l’Helvète!
I could maybe hide a value in a layer name or something like that but the scriptcontent or DocumentData seemed so much more useful