如何访问 Maya 中对象的注释字段

发布于 2024-08-03 19:09:58 字数 92 浏览 2 评论 0原文

是否可以通过 Maya 脚本接口访问对象的“注释”字段?我试图让它在 Python 中工作,但我假设任何指向我需要在 API 中使用的类/函数的正确方向的指针都会帮助我。

Is it possible to access the 'notes' field of an object through the Maya scripting interface? I'm trying to get it to work inside Python, but I assume any pointer into the right direction of which class/function I need to use in the API will help me out.

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

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

发布评论

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

评论(2

黑色毁心梦 2024-08-10 19:09:58

当您在属性编辑器中的注释字段中键入内容时,名为“notes”的属性会动态添加到节点。因此,要检查该值,您可以检查节点上是否存在名为“notes”的属性,然后检索该值。

Maya UI 用于创建和设置 Notes 属性的 mel 过程称为

setNotesAttribute(string $nodeName, string $longAttrName, string $shortAttrName, string $attrType, string $newAttrValue)

其中长名称为 "notes",短名称为 "nts",类型为 <代码>“字符串”。

An attribute called "notes" is added dynamically to nodes when you type in the notes field in the attribute editor. So, to check the value you can check if an attribute called "notes" exists on the node, then retrieve the value.

The mel procedure that the maya UI uses to create and set the notes attribute is called

setNotesAttribute(string $nodeName, string $longAttrName, string $shortAttrName, string $attrType, string $newAttrValue)

Where the long name is "notes", short name is "nts", type is "string".

百思不得你姐 2024-08-10 19:09:58

由于现在每个人都在使用 PyMEL,因此以下是如何使用 PyMEL 获取它:

import pymel.core
# cast selected into PyNode
node = pymel.core.ls(sl=1)[0]

# PyMEL's convenient getAttr syntax
node.notes.get()

假设您已经在属性编辑器的“注释”字段中添加了一些内容。如上所述,注释 attr 仅在那时创建。

如果您从代码中运行所有内容并且不知道注释 attr 是否已创建,您可以像这样检查是否存在:

if node.hasAttr('notes'):
    node.notes.get()
else:
    # go ahead and create attr
    node.addAttr('notes', dt='string')
    node.notes.get()

考虑使用 PyMEL,它就像 maya.cmds,只是更 Pythonic。

Since everyone is using PyMEL these days, here's how to get it using PyMEL:

import pymel.core
# cast selected into PyNode
node = pymel.core.ls(sl=1)[0]

# PyMEL's convenient getAttr syntax
node.notes.get()

This is assuming you've already added something to the Notes field in the attribute editor. As mentioned above the notes attr only gets created then.

If you're running all from code and you don't know if the notes attr has been created, you can check for existence like so:

if node.hasAttr('notes'):
    node.notes.get()
else:
    # go ahead and create attr
    node.addAttr('notes', dt='string')
    node.notes.get()

Consider using PyMEL, it's like maya.cmds, only more Pythonic.

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