简体   繁体   中英

PYTHON in MAYA: get all attributes

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'}

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

You are probably looking for cmds.listAttr()

Doc is available here: Autodesk Maya 2014 Python commands

Usage:

import maya.cmds as cmds

cmds.polyCube( n="myCube")
print cmds.listAttr( "myCube" )

I'd recommand you looking at the available flags to filter some of the attributes ( read flag will fit your needs as it will only return readable attributes).

Note: I didn't check for the pyMel version but I guess this is implemented and works the same way.

Update1: Quick & Dirty way to view all attributes and their type

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

Update2: PyMel doc: listAttr is also available in PyMel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM