Maya Python API 2.0 has no MItDag, so how traverse DAG graph?

做~自己de王妃 提交于 2019-12-13 14:42:59

问题


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?


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



来源:https://stackoverflow.com/questions/20232835/maya-python-api-2-0-has-no-mitdag-so-how-traverse-dag-graph

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!