Skip to content

Instantly share code, notes, and snippets.

@pboucher pboucher/
Created Jan 19, 2011

What would you like to do?
SetValue decorator for Softimage that can temporarily change any value for the duration of a method call and restore it afterward. Originally posted at
@tempSetValues({'preferences.General.undo': 0, 'preferences.scripting.cmdlog': False})
def doStuff(obj):
# Do stuff
# The undo stack will be set to 0 and cmdlog to False before execution and
# restored no matter if the call succeeds or fails.
import functools
xsi = Application
def tempSetValues(newVals):
def closure(func):
def inner(*args, **kwargs):
# Save current values and set new ones
oldVals = {}
for k, v in newVals.iteritems():
oldVals[k] = xsi.GetValue(k)
xsi.SetValue(k, v, "")
# Run the wrapped function
return func(*args, **kwargs)
# Restore the old values
for k, v in oldVals.iteritems():
xsi.SetValue(k, v, "")
return inner
return closure

This comment has been minimized.

Copy link
Owner Author

pboucher commented Jan 19, 2011

Yeah, don't forget that xsi == Application. Doh! I'll fix it when our admin opens git protocol port in the firewall. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.