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
state = sc.sticky["state"]
state = False
rs.MessageBox("changed state to "+ str(state))
state = not state
sc.sticky["state"] = state
if __name__ == "__main__":
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…