gpt4 book ai didi

python - 玛雅 python : getting the position of selected object using getAttr

转载 作者:行者123 更新时间:2023-11-28 16:35:33 25 4
gpt4 key购买 nike

我正在尝试使用 Python 脚本在 Maya 中制作一个简单的“对齐工具”,这就是我的进展

import maya.cmds as cmds

selected = cmds.ls(selection=True)

for all in selected:

cmds.getAttr('Cube.translateX')

这似乎获得了场景中对象名称立方体的 X 位置,但是我希望它获得我选择的任何对象的翻译。

希望有人能帮帮忙,谢谢

最佳答案

在字符串“Cube.translateX”中,您需要用所选对象的名称代替“Cube”。我们在此处使用 %s 格式通过简单的字符串格式来完成此操作:

import maya.cmds as cmds

selected = cmds.ls(selection=True)

for item in selected:
translate_x_value = cmds.getAttr("%s.translateX" % item)
# do something with the value. egs:
print translate_x_value

希望对您有所帮助。

关于python - 玛雅 python : getting the position of selected object using getAttr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26868429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com