3

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

davide
  • 1,918
  • 2
  • 20
  • 30
Morgan
  • 589
  • 9
  • 20

1 Answers1

5

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.

DrHaze
  • 1,318
  • 10
  • 22
  • Thanks @DrHaze, listAttr() work perfectly with pymel. This is exactly what I need. But I'm anyway curious to know where this list of attributes is stored so if someone know it, I'm interested :) (if there is a method similar to `__dict__`) – Morgan May 11 '15 at 13:17
  • 1
    There's no real analogy between a python object and what you get back from maya.cmds -- that's literally just a string, and you need to call commands on it to get the list of attributes attached to an object. Because they can be added dynamically they aren't part of the class definitions. Pymel wraps a handle to the underlying maya object, but the same caveat is basically true. `listAttr` is the way to go. – theodox May 12 '15 at 03:08