Maya Python API 2.0没有MItDag,那么如何遍历DAG图形? [英] Maya Python API 2.0 has no MItDag, so how traverse DAG graph?

查看:237
本文介绍了Maya Python API 2.0没有MItDag,那么如何遍历DAG图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题特定于Autodesk Maya. 使用Maya 2014 SP2.(立即下载SP 3 ...)

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

在使用Maya Python API版本1时,遍历DAG图形是可行的:

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()

但是现在我尝试版本2

But now I try Version 2

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

这会导致错误

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

实际上,第2版文档未显示MItDag.

Indeed, the Version 2 doc shows no MItDag.

如何使用版本2 API遍历场景的DAG图?

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

推荐答案

现在已经与Maya API进行了更深入的合作,答案是:

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

API的版本2非常不完整.它无法做到这一点,也无法完成许多其他高级方案.它的好处是它可以做的事情,更容易编程.

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.

但是,有时不能在API版本1中工作,有时又可以在API版本2中工作,因为不能将一个API中的对象传递给另一个API,所以效果不佳.

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.

因此,一旦程序员超出版本2的限制,正确的解决方案是完全停止使用版本2.

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

恕我直言,这意味着任何认真的程序员都不应该一开始就浪费时间使用版本2,因为它们最终会丢弃该代码.

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.

如果您要寻找一种更轻松的解决方案,而不是直接对版本1 API进行编程,则可以考虑.

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

这篇关于Maya Python API 2.0没有MItDag,那么如何遍历DAG图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆