the maya commands are not fully implemented and I always use the API to reliably find an attribute's type :

        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


On 02/07/10 00:16, Paul Molodowitch wrote:
Unfortunately, what I ultimately need to do is get results similar to
those returned by getAttr(type=1)... this is for the implementation of
PyNode.type(), which has been using getAttr... but I've found it
errors out on the sort of attributes I mentioned.

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

On Thu, Jul 1, 2010 at 1:55 PM, Judah Baron<[email protected]>  wrote:
I think the safest thing to do is to use the attribute's mobject.apiType()
func to get the id. It can be pretty complex though because for the
non-standard types, such as string you have to do multiple lookups. For
instance, a string type will return you a type id of 562, for
kTypedAttribute, not exactly a string type. Then you need to create an
MFnTypedAttribute so you can ask it what its actual type is. You can create
a base type attribute function set, MFnAttribute, to query any attribute
about any of the shared settings, such as isArray, etc.

I'll stop there because I'm not sure if this is of use to you, Paul.

-Judah


On Thu, Jul 1, 2010 at 12:24 PM, Paul Molodowitch<[email protected]>
wrote:
Hey all - I was wondering if anyone here knew of a way to query the
'type' (ie, similar to what getAttr('foo.bar', type=True) would
return) of an attribute, for ANY attribute.  Specifically, I can't
seem to find ANY way to query the type of multi-compound attribute's
children, when the multi does not have any indices created yet.

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

--
http://groups.google.com/group/python_inside_maya
--
http://groups.google.com/group/python_inside_maya

--
http://groups.google.com/group/python_inside_maya

Reply via email to