David l
Is there some helpfull Soul, that can help me with a Small python snippet that returns a given attributes datatype through the Api?

I found this thread that seems to do what i Need but my python Api skills are Just too weak! :/

https://www.mail-archive.com/python_inside_maya@googlegroups.com/msg03534.html
Quote 0 0
pshipkov
I think there is much simpler way to do that.
The idea is that you can getAttr and check the returned data type.

value = mc.getAttr("myNode.myAttr")
t = type(value)
if t == bool: print "boolean"
elif t == int: print "long"
elif t == float: print "double"
elif t == str or t == unicode: print "string"

Of course, this simplification may not be enough if you want need exact attribute type for API level coding.
But for high-level scripting - should be enough.
Quote 0 0
David l
That doesnt work in this situation.... try it on point1.inNormalPP for instance.

I'm trying to create a content aware marking menu for soup. The idea is that it pairs which attributes are suited for connections based on their type, for instance outPositionPP can be plugged into inPositionPP, inNormalPP etc. but not inWeightPP.

I got something nice working for a handfull of soup nodes but its alot of work to both keep track of attributes as well as their type... Not saying it cant be done but it would be nice to get that last part automatically and it would sure make things cleaner and easier to maintain.

Hope it's clear what I'm trying to do, otherwise I'll post a screen recording when back at work :)
Quote 0 0
pshipkov
elif t == list:
    t2 = type(l[0])
    if t2 == int: print "int array"
    elif t2 == float: print "double array"
    elif t2 == str or t2 == unicode: print "string array"
    elif t2 == tuple: print "vector array"

This can get you quite far with no coding effort involved, but if you want to do it for realz you have to do what was in the link you provided.

p = om.MPlug()
sl = om.MSelectionList()
sl.add("myNode.myAttribute")
sl.getPlug(0, p)
print om.MFnNumericAttribute(p.attribute()).unitType()

This will return the numeric value but you can compare it like how is showed in the link you provided.
Quote 0 0
David l
pshipkov wrote: elif t == list:
    t2 = type(l[0])
    if t2 == int: print "int array"
    elif t2 == float: print "double array"
    elif t2 == str or t2 == unicode: print "string array"
    elif t2 == tuple: print "vector array"

This can get you quite far with no coding effort involved, but if you want to do it for realz you have to do what was in the link you provided.

p = om.MPlug()
sl = om.MSelectionList()
sl.add("myNode.myAttribute")
sl.getPlug(0, p)
print om.MFnNumericAttribute(p.attribute()).unitType()

This will return the numeric value but you can compare it like how is showed in the link you provided.


Thanks alot Peter, I believe I can build the rest from here :)
Quote 0 0
David l
Hi Peter

It fails with:

# Error: RuntimeError: file S:\Maya_2016_R2_DI\build\Release\runTime\Python\Lib\site-packages\maya\OpenMaya.py line 6344: (kInvalidParameter): Object is incompatible with this method #



when I try to do this:

Code:

import maya.OpenMaya as om
p = om.MPlug()
sl = om.MSelectionList()
sl.add("point1.inNormalPP")
sl.getPlug(0, p)
print om.MFnNumericAttribute(p.attribute()).unitType()


Do you know what I am doing wrong? Im on Win 7 and maya 2016.5
Quote 0 0
pshipkov
try this:
print om.MFnTypedAttribute(p.attribute()).unitType()
Quote 0 0
David l
Now I get this error:

# Error: AttributeError: file S:\Maya_2016_R2_DI\build\Release\runTime\Python\Lib\site-packages\maya\OpenMaya.py line 54: unitType # 

Here's what I have so far, trying to streamline the connection workflow a bit and make it more accesible, sort of wrench on steroids :)

soup_connector.gif 
Quote 0 0
pshipkov
I reeeeeeally like it !
Do you think i can borrow the idea, or better the code, to slap in SOuP ?

Try this:
print om.MFnGenericAttribute(p.attribute()).unitType()
Few other classes that are often used:
MFnEnumAttribute
MFnMessageAttribute

Quote 0 0
David l
Sure I'll shoot you a pm :)
Quote 0 0

Add a Website Forum to your website.