3

This question is specific to Autodesk Maya. Using Maya 2014, SP 2. (Downloading SP 3 now...)

When using Version 1 of Maya Python API, to traverse DAG graph this works:

import maya.OpenMaya as OM
dagIterator = OM.MItDag( OM.MItDag.kDepthFirst, OM.MFn.kInvalid )
dagNodeFn = OM.MFnDagNode()
# Traverse the scene.
while( not dagIterator.isDone() ):
    ... do stuff with current node on iterator ...
    dagIterator.next()

But now I try Version 2

import maya.api.OpenMaya as OM
dagIterator = OM.MItDag( OM.MItDag.kDepthFirst, OM.MFn.kInvalid )

which results in error

# Error: line 1: AttributeError: file <maya console> line 1: 'module' object has no attribute 'MItDag' # 

Indeed, the Version 2 doc shows no MItDag.

How traverse the scene's DAG graph, using Version 2 API?

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
  • For your purpose, traversing through invalid dag nodes, I would suggest you stick with 1.0 API though. Python API 2.0 is still lack of something now. – Drake Guan Dec 09 '13 at 05:21
  • @Drake, that is my conclusion also. In fact, API 2.0 is so incomplete, that I have stopped using it entirely. – ToolmakerSteve Aug 07 '14 at 05:40

1 Answers1

1

Having worked with Maya API's in much greater depth now, the answer is:

Version 2 of the API is VERY incomplete. It cannot do this, nor can it do many other advanced scenarios. Its benefit is that what it can do, is much simpler to program.

However, sometimes working in API version 1 and sometimes working in API version 2 does not work well, because an object from one API cannot be passed to the other API.

As a result, once a programmer has exceeded the limitations of version 2, the correct solution is to stop using version 2 completely.

IMHO, this means any serious programmer should not waste their time with version 2 in the first place, because they will end up throwing away that code.


If you are looking for an easier solution than directly programming the version 1 APIs, then consider "PyMel" library.

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
  • NOTE: At some point in the future, this will allegedly stop being accurate, and API version 2 will be usable for serious work. If you reach this Q&A in 2015 or later, look for more recent discussion. – ToolmakerSteve Sep 11 '14 at 18:04
  • Also: for dag node traversal cmds.ls() is usually competitive -- or even faster -- then api 1's MItDag. If you're not in a plugin, ls() + api2 is at least as good and possibly better than api 1. Pymel is 3rd in speed terms – theodox Feb 24 '16 at 18:03