Determining if object is a DAG node

2,094 views
Skip to first unread message

Jeremy YeoKhoo

unread,
May 23, 2014, 12:38:39 AM5/23/14
to python_in...@googlegroups.com
(Sorry I posted this up before but tried to edit it.)


Hi guys,

This is a bit silly. But... 
I am trying to determine if a queried object is a dag node or a shape node because my current example code has the following.... 

import maya.cmds as cmds

obj= cmds.polySphere(r= 1, sx= 20, sy= 20, ax=[0, 1, 0], cuv= 2, ch= 0) 
cmds.select(obj, r=1)
sels= cmds.ls(sl=1)
result= cmds.listRelatives(sels[0],c=1, s=0)

within result, I still get a shape object in the list....
So the way I check if it is a DAG node, I would then

for r in result:
    
if cmds.objExists(r+"tx"):
       
print "This is daggy"


Is there a better way of coding this? 

-Jeremy

Marcus Ottosson

unread,
May 23, 2014, 1:45:56 AM5/23/14
to python_in...@googlegroups.com

Hi Jeremy,

Almost all nodes in Maya is inherited from some other node; e.g. shape inherits dagNode.

You can query this inheritance using the cmds.nodeType command:

from maya import cmds

if 'dagNode' in cmds.nodeType('pCubeShape1', inherited=True):
    print "This is a dag node"


--
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/1751a6c9-4611-45ae-b92f-dbcb41e14a56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Jeremy YeoKhoo

unread,
May 23, 2014, 3:10:03 AM5/23/14
to python_in...@googlegroups.com
Gah! Of course thanks again Marcus :)

Arjun Thekkummadathil

unread,
May 23, 2014, 3:20:09 AM5/23/14
to python_in...@googlegroups.com
if you say
ls -dag

it will list only dag objects


--
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.

Marcus Ottosson

unread,
May 23, 2014, 5:24:27 AM5/23/14
to python_in...@googlegroups.com

Gah! Of course thanks again Marcus :)

You’re welcome. :)




For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Paul Molodowitch

unread,
May 23, 2014, 9:35:22 AM5/23/14
to python_inside_maya
Also, a more direct way of querying if an object is a specific type of node is:

cmds.objectType(myNode, isAType='transform')

...which will return True for all transforms and joints (which inherit from transforms), for instance.

Using cmds.nodeType(myNode, inherited=True) has the added bonus of helping you learn the inheritance hiearchy, though...


Jeremy YeoKhoo

unread,
May 23, 2014, 7:45:20 PM5/23/14
to python_in...@googlegroups.com
Thanks for that elrond79


On Friday, 23 May 2014 14:38:39 UTC+10, Jeremy YeoKhoo wrote:
Reply all
Reply to author
Forward
0 new messages