To see what I mean:
import maya.cmds as cmds
def getType(node):
print "%-50s :" % node,
try:
print cmds.getAttr(node, type=True)
except Exception:
print "<ERROR>"
getType(u'persp.publishedNodeInfo')
getType(u'persp.publishedNodeInfo.publishedNode')
getType(u'persp.publishedNode')
getType(u'persp.publishedNodeInfo[-1].publishedNode')
getType(u'persp.instObjGroups.objectGroups')
getType(u'persp.instObjGroups.objectGroups.objectGroupId')
getType(u'persp.objectGroupId')
Is there another way to query the type of an attribute other than
getAttr? attributeQuery doesn't seem to have any relevant flags, and I
couldn't find any way to access this information from the API.
Any ideas?
- Paul
I may ultimately have to do some sort of branched logic similar to
what you suggest, and try to find out all the possible types returned
by getAttr, and implement my own mapping to them, etc... but I'd like
to avoid that if at all possible...
- Paul
attrObj = attrPlug.attribute()
if attrObj.hasFn( om.MFn.kNumericAttribute ):
fnAttr = om.MFnNumericAttribute(attrObj)
realtype = fnAttr.unitType()
if realtype == om.MFnNumericData.kBoolean:
...
elif realtype == om.MFnNumericData.kByte:
...
elif realtype == om.MFnNumericData.kChar:
...
elif realtype == om.MFnNumericData.kShort:
...
elif realtype == om.MFnNumericData.kLong:
...
elif realtype == om.MFnNumericData.kFloat:
...
elif realtype == om.MFnNumericData.kDouble:
...
elif realtype == om.MFnNumericData.k3Float:
...
elif realtype == om.MFnNumericData.k3Double:
...
else:
raise drh.Error( '[ MayaAttr ] Unknown
kNumericAttribute : %s.%s.%s' % (node,attr,subattr) )
elif attrObj.hasFn( om.MFn.kTypedAttribute ):
fnAttr = om.MFnTypedAttribute(attrObj)
realtype = fnAttr.attrType()
if realtype == om.MFnData.kString:
...
if realtype == om.MFnData.kStringArray:
...
if realtype == om.MFnData.kDoubleArray:
...
if realtype == om.MFnData.kIntArray:
...
else:
m = '[ MayaAttr ] Unknown kTypedAttribute :
%s.%s.%s' % (node,attr,subattr)
raise drh.Error( m )
elif ...
Further to that, you would have to make sure you are not looking at a
compound attr. If so, get the children plugs and run that sort of code...
philippe
- Paul