Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PYTHON in MAYA: get all attributes

Tags:

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

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

like image 873
Morgan Avatar asked Sep 20 '26 17:09

Morgan


1 Answers

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.

like image 70
DrHaze Avatar answered Sep 22 '26 08:09

DrHaze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!