Get a plug for an aliased multi / compound plug in API

455 views
Skip to first unread message

Paul Molodowitch

unread,
Jan 23, 2011, 10:14:52 PM1/23/11
to python_inside_maya
Hey all - so, I have an alias which refers to an multi-compound attribute:

import maya.cmds as cmds

remap = cmds.createNode('remapValue')

cmds.aliasAttr ('alfred', remap + '.value[0].value_Position')

print cmds.aliasAttr(remap, q=1)


So far so good. Now, using the api, and starting with just the alias name, I want to be able to get an MPlug for the plug it points to.  Unfortunately, I haven't found a way to do this.  The obvious way - using MFnDependencyNode.findAlias - only gives me a plug for the base attribute, not the specific index / child the alias actually refers to:


import maya.OpenMaya as om


sel = om.MSelectionList()

sel.add(remap)


obj = om.MObject()

sel.getDependNode(0, obj)

mfn = om.MFnDependencyNode(obj)


attr = om.MObject()

mfn.findAlias('alfred', attr)

plug = om.MPlug(obj, attr)


print plug.partialName(True, True, True, False, True, True)



However, what we end up with is remapValue1.value, not remapValue1.value[0].value_Position


Should I just be using getAliasList, and then feeding the text string into an MSelectionList?  If so, what's the point of findAlias?


- Paul

Miguel González Viñé

unread,
Aug 27, 2012, 4:29:09 PM8/27/12
to python_in...@googlegroups.com
Did you solve this or anyone knows how to get the MPlug from the alias name in a MFnDependencyNode?
Also I've tried with getAliasAttr but I don't know what to do with the returned MObject.

Thank you!


Paul Molodowitch

unread,
Aug 28, 2012, 9:29:20 PM8/28/12
to python_in...@googlegroups.com
If I recall correctly, I just had to do  a getAliasAttr / MSelectionList combo, as I suggested.  Not sure when you would want to use findAlias (since it seems unreliable)...

- Paul


Miguel González Viñé

unread,
Aug 29, 2012, 4:22:27 AM8/29/12
to python_in...@googlegroups.com
Thanks for your reply Paul.

Did you mean getAliasList instead of getAliasAttr, right? With this option I get a list with the aliases, but the names of the attributes are included too:

import maya.OpenMaya as om

list = om.MSelectionList()

node = om.MObject()

list.add("blendShape1")

list.getDependNode(0, node)

dgNode = om.MFnDependencyNode(node)

aliasList = []

dgNode.getAliasList(aliasList)

# Result: [u'pSphere2', u'weight[0]', u'pSphere3', u'weight[1]'] #


 I don't understand the MSelectionList combo, could you explain it please?


Thank you Paul.

Paul Molodowitch

unread,
Aug 29, 2012, 1:43:54 PM8/29/12
to python_in...@googlegroups.com
Yes, I meant getAliasList.
By the "MSelectionList combo", I simply meant that in order to turn the strings you get back from getAliasList into MObjects - which you can then use to do things with in the api - you need to use MSelectionList.add / MSelectionList.getPlug
It may also be possible to just use MFnDependencyNode.findPlug, instead of MSelectionList... I'm not sure offhand how it handles child/multi attributes.
- Paul

Miguel González Viñé

unread,
Aug 29, 2012, 2:09:58 PM8/29/12
to python_in...@googlegroups.com
Great, thanks for the explanation.
Reply all
Reply to author
Forward
0 new messages