如何在maya python中使用字典

时间:2018-04-26 12:21:51

标签: python maya

我尝试在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()

由于

1 个答案:

答案 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()