Discussion:
[Maya-Python] [MPlug] error on get attribute
Rémi Deletrain
2018-06-22 09:17:56 UTC
Permalink
I everyone,

I found an error on get attribute "rotatePivot" with api.

It's possible to get this attribute with MFnDependencyNode like this

m_sl = OpenMaya.MSelectionList()
m_sl.add("null1")

mo = OpenMaya.MObject()
m_sl.getDependNode(0, mo)

mfn = OpenMaya.MFnDependencyNode(mo)
mp = mfn.findPlug("rotatePivot")

But is not possible to get this attribute with MSelectionList

m_sl = OpenMaya.MSelectionList()
m_sl.add("null1.rotatePivot")

mp = OpenMaya.MPlug()
m_sl.getPlug(0, mp)

But it's possible to get children like this

m_sl = OpenMaya.MSelectionList()
m_sl.add("null1.rotatePivotX")

mp = OpenMaya.MPlug()
m_sl.getPlug(0, mp)

It's normal ?
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9aae0c9a-9897-4d5d-87bb-5fbc23e9a3ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Cedric Bazillou
2018-06-23 19:53:52 UTC
Permalink
Depends on what your trying to achieve.
selection list first usage is for dag/dependency node and components.

Once you access them you can access their attributes easily
So at first read what you point out doesn't look like an error.
Post by Rémi Deletrain
I everyone,
I found an error on get attribute "rotatePivot" with api.
It's possible to get this attribute with MFnDependencyNode like this
m_sl = OpenMaya.MSelectionList()
m_sl.add("null1")
mo = OpenMaya.MObject()
m_sl.getDependNode(0, mo)
mfn = OpenMaya.MFnDependencyNode(mo)
mp = mfn.findPlug("rotatePivot")
But is not possible to get this attribute with MSelectionList
m_sl = OpenMaya.MSelectionList()
m_sl.add("null1.rotatePivot")
mp = OpenMaya.MPlug()
m_sl.getPlug(0, mp)
But it's possible to get children like this
m_sl = OpenMaya.MSelectionList()
m_sl.add("null1.rotatePivotX")
mp = OpenMaya.MPlug()
m_sl.getPlug(0, mp)
It's normal ?
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2fcee142-c8c3-4870-894a-986eaff61c8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Rémi Deletrain
2018-06-28 16:05:19 UTC
Permalink
I want to get a vector attribute like *translate*.
Attribute *translate* and *rotatePivot* is a same type. But get rotatePivot
doesn't work and get translate works fine.

from maya import OpenMaya

def get_mplug(s_attr_node):
m_sl = OpenMaya.MSelectionList ()
m_sl.add (s_attr_node)
mp = OpenMaya.MPlug ()
m_sl.getPlug (0, mp)
return mp

try:
mp_translate = get_mplug("joint1.translate")
print mp_translate.child(0).name()
print mp_translate.child(1).name()
print mp_translate.child(2).name()
except:
print "Get translate doesn't works"
else:
print "Get translate works"

try:
mp_rotate_pivot = get_mplug("joint1.rotatePivot")
print mp_rotate_pivot.child(0).name()
print mp_rotate_pivot.child(1).name()
print mp_rotate_pivot.child(2).name()
except:
print "Get rotatePivot doesn't works"
else:
print "Get rotatePivot works"
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ce3b762c-bdfd-4c7e-9fe3-385fa89793d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Cedric Bazillou
2018-06-29 08:35:13 UTC
Permalink
oh i know pretty much every part of the api related to animation / rigging.
Im just pointing out that in order to use the API in python you have to
follow some strict procedure ( automatic binding with swig)

import maya.OpenMaya as OpenMaya
def getMObject(nodeName):
selList = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getSelectionListByName(nodeName, selList)
depNode = OpenMaya.MObject()
selList.getDependNode(0, depNode)

return depNode


nodeFn = OpenMaya.MFnDependencyNode(getMObject('joint1'))
matrixPlug = nodeFn.findPlug('rotatePivot')

for childIndex in range(matrixPlug.numChildren()):
print matrixPlug.child(childIndex).asFloat()


Hence me getting a plug from dependency Mfn function set and not fiddling
with the MSelectionList ( which conceptually is for dag/dependency and
components).
Most of the time when working with python programmer, or other artist i
have to point out that the api is exposed and use some python syntax but
you must adopt maya philosophy ( so asking for more pythonic doesnt make
sense : at some point
you will write it in c++ and your python code will be a waste of time to
translate back to pure API)
Post by Rémi Deletrain
I want to get a vector attribute like *translate*.
Attribute *translate* and *rotatePivot* is a same type. But get
rotatePivot doesn't work and get translate works fine.
from maya import OpenMaya
m_sl = OpenMaya.MSelectionList ()
m_sl.add (s_attr_node)
mp = OpenMaya.MPlug ()
m_sl.getPlug (0, mp)
return mp
mp_translate = get_mplug("joint1.translate")
print mp_translate.child(0).name()
print mp_translate.child(1).name()
print mp_translate.child(2).name()
print "Get translate doesn't works"
print "Get translate works"
mp_rotate_pivot = get_mplug("joint1.rotatePivot")
print mp_rotate_pivot.child(0).name()
print mp_rotate_pivot.child(1).name()
print mp_rotate_pivot.child(2).name()
print "Get rotatePivot doesn't works"
print "Get rotatePivot works"
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9510eb6d-579a-4cdd-9992-54bd53158ce3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Rémi Deletrain
2018-07-04 07:47:23 UTC
Permalink
Merci de ta réponse Cédric.

Je comprend bien l'utilité de réfléchir en cpp et non pas en python.
J'essaye de le faire au maximum et j'ai réussi à optimiser pas mal de code
grâce à ça.
Parfois j'utilise des "racourcis" pour aller un peu plus vite dans le
prototypage, comme la fonction getPlug du MSelectionList.
Je fais aussi en fonction de ce que l'on me donne, ici un json qu'avec des
string et donc la fonction getPlug lorsque j'ai "myNode.myAttribute" permet
d'aller "vite" en code. Mais du coup ça oblige soit à couper la chaine de
character soit à repenser la logique de génération de fichier qui n'est pas
basé sur l'api maya. A terme ça viendra mais pour le moment on est en phase
de test et de transformation de certain script.

Seulement le fait que getPlug fonctionne avec l'attribut "translate" et pas
"rotatePivot" m’interpelle. Pour moi ce sont des attributs d'un même type.
Mais comme la récupération ne fonctionne pas il y a forcement une
différence et je cherche a savoir laquelle.

Thank you for your answer Cédric.

I understand the usefulness of thinking in cpp and not in python. I try to
do it as much as possible and I optimize a lot of code thanks to that.
Sometimes I use "shortcuts" to go a little faster in prototyping, like the
getPlug function of the MSelectionList.
I also do according to what I am given, here a json with string and thus
the function getPlug when I have "myNode.myAttribute" to go "fast" in code.
But it forces either to cut the string or to rethink the file generation
logic that is not based on the Maya API. Eventually it will come but for
the moment we are in phase of test and transformation of some script.

Only the fact that getPlug works with the attribute "translate" and not
"rotatePivot" calls me. For me, they are attributes of the same type.
But as the recovery does not work there is necessarily a difference and I
want to know which one.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/689ad3a6-5823-4ecb-b8d1-7b12308acc8a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Rémi Deletrain
2018-07-04 07:47:48 UTC
Permalink
Thank you for your answer Cédric.

I understand the usefulness of thinking in cpp and not in python. I try to
do it as much as possible and I optimize a lot of code thanks to that.
Sometimes I use "shortcuts" to go a little faster in prototyping, like the
getPlug function of the MSelectionList.
I also do according to what I am given, here a json with string and thus
the function getPlug when I have "myNode.myAttribute" to go "fast" in code.
But it forces either to cut the string or to rethink the file generation
logic that is not based on the Maya API. Eventually it will come but for
the moment we are in phase of test and transformation of some script.

Only the fact that getPlug works with the attribute "translate" and not
"rotatePivot" calls me. For me, they are attributes of the same type.
But as the recovery does not work there is necessarily a difference and I
want to know which one.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/30f2858d-1ca7-428c-9bdb-b147cb3a6cfc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...