我尝试在maya python上学习词典。
我想记录一些物体的旋转,我稍后会用它 它正在努力记录价值,但是当我打电话给词典时,它总是给我“无”答案
import maya.cmds as cmds
myDic = {}
def test():
mods = cmds.getModifiers()
SELlis = cmds.ls(sl = 1)
a = 0
b = 1
if mods == 4:
for obj in SELlis:
myDic[obj] = cmds.getAttr(obj+'.rotate')
else :
for obj in SELlis:
if obj in myDic:
print myDic.get(obj)
else :
print 'none'
test()
由于
答案 0 :(得分:0)
抱歉我的错,我一开始就创建'myDic = {}',所以每次按下按钮都会将'myDic'重置为无
import maya.cmds as cmds
def test():
global myDic
mods = cmds.getModifiers()
SELlis = cmds.ls(sl = 1)
if mods == 4:
myDic = {}
for obj in SELlis:
myDic[obj] = cmds.getAttr(obj+'.rotate')
else :
for obj in SELlis:
if obj in myDic:
print myDic.get(obj)
else :
print 'none'
test()