简体   繁体   English

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

[英]Dynamic Node Names in MEL Expressions

You know how if you change a nodeName in an expression it will also change the name inside of it as well? 您知道如何在表达式中更改nodeName,它也将同时更改其内部的名称吗? Well, how do we go about doing this for stuff like a pointPosition, where the nodeName is inside of a string? 好吧,我们如何针对诸如pointPosition之类的东西执行此操作,其中nodeName在字符串内部?

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! 如果将outputCloth1的名称更改为myCloth,则该表达式将停止工作,因为字符串仍然显示outputCloth1!

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. 不幸的是,简短的答案是,您不能(轻松)..节点内的表达式可能会被Maya保留,因为它位于Maya主动监视的框架的一部分内。 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: 对于您的脚本,不能这么说,因为对于Maya来说,只要您告诉它,它只是一堆文本,它可以读取和处理...两个选项本身就可以显示出来:

  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. (如果可能的话)您可以重写表达式以动态引用对象 。例如,如果您知道outputCloth1始终是masterObjectGroup15的子代,则可以选择第一个子代,而不用按名称进行引用。

  2. Move into PyMEL . 进入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. 类似于#1,因为您将要引用该对象,并且如果更改名称,则对该对象的引用仍然有效。 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 (可能)超出了答案的范围,但我强烈建议您查看PyMEL入门文档,因为它们首先给出了一个很好的示例

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. 您还可以考虑通过Maya API构建DG节点-与脚本编写相比,它的设置工作要多得多,但是您正在做的事情是构建适合标准Maya框架(基本上是自定义节点)的东西-意味着您可以利用Maya为您做的所有内部整理工作。 Yay! 好极了!

I think you might be able to achieve what you're looking for via the message attribute. 我认为您可以通过message属性来实现所需的功能。 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. 消息用于在Maya中将节点链接在一起,(除其他事项外)消息可以构成脚本的基础,这些脚本会在重命名节点时自动更新名称。

Sorry I don't have a more concrete example atm, but look into message- that should get you going in the right direction. 抱歉,我没有更具体的自动取款机示例,但是请仔细阅读消息-应该可以使您朝正确的方向前进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM