Skip to content

Instantly share code, notes, and snippets.

@mottosso
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mottosso/24b88b4df1bbdca09a11 to your computer and use it in GitHub Desktop.
Save mottosso/24b88b4df1bbdca09a11 to your computer and use it in GitHub Desktop.
Imprint and restore default values
"""Store and restore default values
Current keyable values are stored in a `defaults` attribute
within each node using `store()` and later restored using
`restore()`. This way, channels which could otherwise not
have a native default value (such as plain transform and rotate)
may carry defaults alongside user-defined attributes.
"""
import json
def store(node):
"""Store current values as default values"""
defaults = dict()
for attr in cmds.listAttr(node, keyable=True):
value = cmds.getAttr("%s.%s" % (node, attr))
defaults[attr] = value
defaults_string = json.dumps(defaults)
if not cmds.objExists(node + ".defaults"):
cmds.addAttr(node, ln="defaults", dt='string')
cmds.setAttr(node + ".defaults", defaults_string, type='string')
def store_selected():
for node in cmds.ls(sl=1):
store(node)
def restore(node):
"""Restore defaults from imprint"""
defaults = cmds.getAttr(node + ".defaults")
defaults_dict = json.loads(defaults)
for key, value in defaults_dict.iteritems():
cmds.setAttr(node + ".%s" % key, value)
def restore_selected():
for node in cmds.ls(sl=1):
restore(node)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment