Skip to content

Instantly share code, notes, and snippets.

@fredrikaverpil
Last active September 7, 2018 04:41
Show Gist options
  • Save fredrikaverpil/9973865 to your computer and use it in GitHub Desktop.
Save fredrikaverpil/9973865 to your computer and use it in GitHub Desktop.
Using Json To Store Node Information #maya
# Copy-pasted from http://www.mattmurrayanimation.com/using-json-to-store-node-information-in-maya/
import json
import pymel.core as pm
def store(name, objs):
pose={}
ctrls=[]
for o in objs:
data={}
for attr in pm.listAttr(str(o), keyable=True, unlocked=True):
value = pm.getAttr(str(o)+'.'+attr)
data.setdefault(str(attr),value)
ctrls.append([str(o),[data]])
pose.setdefault(name, {"ctrls":ctrls})
f=open('/Users/yourname/Desktop/' + name + '.rp', 'w')
f.write(json.dumps(pose))
f.close()
def load(poseToLoad):
f=open('/Users/yourname/Desktop/' + poseToLoad +'.rp', 'r')
data=f.readlines()
f.close()
j_data = json.loads(data[0])
ctrls = j_data[poseToLoad]['ctrls']
for c in ctrls:
ctrl = c[0]
attrs = pm.listAttr(ctrl, keyable=True, unlocked=True)
for a in attrs:
at = c[1][0]
val = c[1][0][a]
pm.setAttr(ctrl + '.' + a, val)
if len(pm.ls(sl=True)):
objs = pm.ls(sl=True)
# store("pose1",objs)
load("pose1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment