Getting the Transform from a Mesh vertices with OpenMaya

326 views
Skip to first unread message

Jeremy YeoKhoo

unread,
Jul 23, 2014, 5:07:41 AM7/23/14
to python_in...@googlegroups.com
Hey guys,

I am trying to return the transform node of a components. So say for an example I select vertices or faces, etc... of a mesh, and I want to return the name of the Transform. This is my code:

import maya.cmds as cmds
import maya.OpenMaya as OpenMaya

meshes= []
sels= cmds.ls(sl=1)
MSel = OpenMaya.MSelectionList()
for i, each in enumerate(sels):
    if cmds.nodeType(each) != "mesh":
        assert False
    else:
        MSel.add(each, i)
        ##MObj= OpenMaya.MObject()
        MDagPath= OpenMaya.MDagPath()
        MSel.getDagPath(0, MDagPath)
        dagObj = MDagPath.transform().__str__()
        print dagObj
        if dagObj not in meshes:
            meshes.append(dagObj)

Now the weird thing is, this worked before and returned the name of my transform and when I re opened a Maya, the same bit of code is now giving me a pointer. 

Any help would be awesome.

Thanks
-Jeremy

mgidney

unread,
Jul 23, 2014, 5:18:59 AM7/23/14
to python_in...@googlegroups.com
Not sure
but you should use a Set  for meshes not a list saves the last test….

MAtt

--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/bce21f4c-6ab7-47b2-ac0a-452aae60e0c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeremy YeoKhoo

unread,
Jul 23, 2014, 5:53:26 AM7/23/14
to python_in...@googlegroups.com
Thanks Matt :) I guess that is better for dealing them as objects? 


I found out how to get the path name though

dagObj = MDagPath.transform()
result= OpenMaya.MFnDagNode(dagObj)
obj = result.partialPathName()  


Reply all
Reply to author
Forward
0 new messages