This is my first real shot at dealing with attrs and plugs in the
API.  I'm trying to do something pretty simple:  If an attr is type
string, query and print the value.  I have this working with just
about every other attr type, but string is causing the code to crash
\exit with no errors or warnings.

In the below example, I've created a simple poly plane (with only 4
verts).  I then walk it's plug hierarchy for the uvSet attr.  After
I've collected all the plugs & child plugs, I loop over them seeing if
they're of type string, and if so, get their value.

However, I'm failing terribly.  As mentioned, whenever I comment out
either of the two "methods" I've come up with below, the code quits
running on that loop with no errors or warnings.  try\except doesn't
help.  What am I missing people? ;)

#------------------
import maya.OpenMaya as om

attr = 'uvSet'
node = "pPlaneShape1"

# Get an MObject by string name:
selList = om.MSelectionList()
selList.add(node)
mObject = om.MObject()
selList.getDependNode(0, mObject)

# Get a plug based on the attribute name:
mFnDependencyNode = om.MFnDependencyNode(mObject)
rootPlug = mFnDependencyNode.findPlug(attr)

plugs = [rootPlug]
# get the MPlug for the compound attribute
for plug in plugs:
    if plug.isCompound():
        for i in range(plug.numChildren()):
            plugs.append(plug.child(i))

# Now query values:
for plug in plugs:
    attr = plug.attribute() # MObject
    if attr.hasFn(om.MFn.kTypedAttribute):
        attrFn = om.MFnTypedAttribute(attr)
        attrType = attrFn.attrType()
        if attrType == om.MFnData.kString:
            val = 'I wish I knew'

            # Method A:
            #stringData = om.MFnStringData(plug.asMObject())
            #val = stringData.string()

            # Method B:
            #val = plug.asString()

            print plug.name(), val

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to