getDagPath in Maya API 2.0?

getDagPath in Maya API 2.0?

j.victor.ferreira
Enthusiast Enthusiast
810 Views
2 Replies
Message 1 of 3

getDagPath in Maya API 2.0?

j.victor.ferreira
Enthusiast
Enthusiast

Hi guys!
Could somebody help me?
I am trying to get the MDagPath in the API 2.0. My code in the old api is working fine:

 

def getMDagPath_old(name):
dag = om.MDagPath()
sel = om.MSelectionList()
sel.add(name)
sel.getDagPath(0, dag)
return dag

 

But in the 2.0 is not working… its returning the name instead of the MDagPath Object:

 

def getMDagPath_new(name):
    sel = new_om.MSelectionList()
    sel.add(name)
    dag = sel.getDagPath(0)
    return dag

 

For sure its a very very beginner doubt, but I can´t solve, Im sorry and thanks for attention!

Accepted solutions (1)
811 Views
2 Replies
Replies (2)
Message 2 of 3

e_honda
Enthusiast
Enthusiast
Accepted solution

Hi,

 

I tested your Python API 2.0 code and, indeed, it returns a MDagPath object.

If you print() the function result, it shows the name of the object (because of its __str__ implementation).

But if you check the result's type, you can see that it is an instance of MDagObject.

 

from maya.api import OpenMaya as new_om

def getMDagPath_new(name):
    sel = new_om.MSelectionList()
    sel.add(name)
    dag = sel.getDagPath(0)
    return dag

name = 'pCubeShape1'
dag = getMDagPath_new(name)

# shows the shape name
print(dag)
# <class 'OpenMaya.MDagPath'>
print(type(dag))
# True
print(isinstance(dag, new_om.MDagPath))

 

Hope it helps.

Message 3 of 3

j.victor.ferreira
Enthusiast
Enthusiast

thank you very much!!!

0 Likes