MEL 表达式中的动态节点名称

发布于 2024-10-19 23:00:52 字数 251 浏览 1 评论 0原文

您知道如果更改表达式中的节点名称,它也会更改其内部的名称吗?那么,对于像 pointPosition 这样的节点名称位于字符串内部的东西,我们该如何做呢?

例如:

vector $v = `pointPosition -world "outputCloth1.vtx[11]"`;

如果将outputCloth1的名称更改为myCloth,则表达式将停止工作,因为字符串仍然显示outputCloth1!

You know how if you change a nodeName in an expression it will also change the name inside of it as well? Well, how do we go about doing this for stuff like a pointPosition, where the nodeName is inside of a string?

For example:

vector $v = `pointPosition -world "outputCloth1.vtx[11]"`;

If you change outputCloth1’s name to myCloth then the expression stops working, because the string still says outputCloth1!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

第七度阳光i 2024-10-26 23:00:52

不幸的是,简短的回答是您不能(轻松).. 节点内的表达式可以由 Maya 进行管理,因为它位于 Maya 主动监控框架的一部分内。对于您的脚本来说,情况并非如此,因为对于 Maya 来说,它只是一堆文本,只要您告诉它,它就会读取和处理...有两个选项会出现:

  1. (如果可能)您可以重写表达式以动态引用对象例如,如果您知道outputCloth1始终是masterObjectGroup15的子级,则可以选择第一个子级,而不是按名称引用。

  2. 进入 PyMEL。这有点像#1,因为您将引用该对象,并且如果更改名称,对该对象的引用仍然有效。这可能(好吧,确实如此)超出了答案的范围,但我强烈建议您查看 PyMEL 入门文档,因为他们首先给出了一个很好的示例

您还可以考虑通过 Maya API 构建 DG 节点 - 与脚本编写相比,它需要更多的设置工作,然而,您正在做的是构建适合标准 Maya 框架的东西(基本上,它是一个自定义节点) - 这意味着您可以利用 Maya 为您所做的所有内部管理。耶!

Unfortunately, the short answer is that you can't (easily).. expressions within a node can be sort of housekept by Maya because it lives within a portion of Maya's actively monitored framework. The same can't be said for your script because to Maya it's just a bunch of text that it reads and processes whenever you tell it to... Two options sort of present themselves:

  1. (If possible) you can rewrite your expressions to refer to objects dynamically For example, if you knew that outputCloth1 was always going to be a child of masterObjectGroup15, you could instead select the first child, instead of referencing by name.

  2. Move into PyMEL. This sort of is like #1, in that you're going to be referencing the object and if you change the name, the reference to the object will still be valid. It's probably (okay, it is) beyond the scope of an answer to go into, but I'd strongly suggest you look at the PyMEL getting started docs since they give a pretty good example first up

You could also look into building DG nodes via the Maya API - it's a lot more setup work when compared to scripting, however what you're doing is building something that fits into the standard Maya framework (it's a custom node, basically) - which means you're able to take advantage of all the internal housekeeping that Maya does for you. Yay!

三寸金莲 2024-10-26 23:00:52

我认为您也许能够通过消息属性实现您正在寻找的内容。消息用于在 Maya 中将节点链接在一起,这(除其他外)可以构成脚本的基础,在重命名节点时自动更新名称。

抱歉,我没有更具体的自动取款机示例,但请查看消息 - 这应该会让您朝着正确的方向前进。

I think you might be able to achieve what you're looking for via the message attribute. Messages are used to link nodes together in Maya, which (amongst other things) can form the basis of scripts that automatically update names as nodes are renamed.

Sorry I don't have a more concrete example atm, but look into message- that should get you going in the right direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文