PYTHON in MAYA: get all attributes

Mor*_*gan 3 python maya

I would like to know if there is a way to get the list of attributes that we can get with pymel.core.getAttr() (or maya.cmds.getAttr() for cmds users). __dict__ doesn't give that list.

import pymel.core as pmc

myCubeTrans, myCubeShape = pmc.polyCube()

>>> print myCubeTrans.__dict__

{'__apiobjects__': {'MDagPath': <maya.OpenMaya.MDagPath; proxy of <Swig Object of type 'MDagPath *' at 0x00000000132ECCC0> >, 'MObjectHandle': <maya.OpenMaya.MObjectHandle; proxy of <Swig Object of type 'MObjectHandle *' at 0x00000000132EC9F0> >, 'MFn': <maya.OpenMaya.MFnTransform; proxy of <Swig Object of type 'MFnTransform *' at 0x00000000132ECA80> >}, '_name': u'pCube1'}

>>> print myCubeShape.__dict__

{'__apiobjects__': {'MObjectHandle': <maya.OpenMaya.MObjectHandle; proxy of <Swig Object of type 'MObjectHandle *' at 0x000000001326DD50> >, 'MFn': <maya.OpenMaya.MFnDependencyNode; proxy of <Swig Object of type 'MFnDependencyNode *' at 0x00000000132ECD50> >}, '_name': u'polyCube1'}
Run Code Online (Sandbox Code Playgroud)

So I would like to know where python is looking for when it executes pmc.getAttr(myCubeTrans.translate) (or myCubeTrans.translate.get() or myCubeTrans.getTranslation())

DrH*_*aze 5

您可能正在寻找cmds.listAttr()

文档可在此处获取:Autodesk Maya 2014 Python 命令

用法:

import maya.cmds as cmds

cmds.polyCube( n="myCube")
print cmds.listAttr( "myCube" )
Run Code Online (Sandbox Code Playgroud)

我建议您查看可用的标志来过滤一些属性(read标志将满足您的需求,因为它只会返回可读的属性)。

注意: 我没有检查 pyMel 版本,但我猜这是实现的并且工作方式相同。

更新1:查看所有属性及其类型的快速而肮脏的方法

for attr in cmds.listAttr( "myCube", r=True ):
    try:
        print attr, " ", cmds.getAttr("myCube."+attr)
    except:
        print "Error reading data"
Run Code Online (Sandbox Code Playgroud)

Update2: PyMel 文档:listAttr在 PyMel 中也可用。