python - 在 Maya 中使用 Python 引用结果

标签 python scripting maya

我一直在 Maya 中编写一个脚本,该脚本将允许我使用摄像机而无需一直进入属性编辑器。目前我有一个带有菜单项的菜单,并且在该菜单项中我也有事件的复选框标志。当切换复选框按钮时,它会运行一个命令来打印复选框的结果。我想做的是有一个 if 语句,它将切换任何相机中的 dof 属性,但通过读取复选框标志的结果来实现这一点。我知道如何正确使用 if 语句 并找到正确的相机,但我不知道如何查询结果。下面是一些脚本,第四行,if 语句,是我遇到问题的地方。感谢您的帮助!

#Window Functions go here

def dofToggle(self):
    print(cmds.menuItem("dof", q=1, cb=1))

    # query the result
    if (cmds.menuItem("dof") == 1):
        cmds.setAttr(camera1.dof=True)

    # window settings go here
    if (cmds.window("Camera Tools", exists=True)):
        cmds.deleteUI("Camera Tools")

    cmds.window(title="Camera Tools", nestedDockingEnabled=True, rtf=True, sizeable=False, menuBar=True, menuBarResize=True, menuBarVisible=True)

    cmds.menu(label="dof")

    cmds.menuItem("dof", label="on/off", checkBox=True, command=dofToggle)

最佳答案

要获取相机的 DOF,请使用以下命令:

import maya.cmds as cmds
print(cmds.camera('cameraShape1', q=True, dof=True))

要禁用相机的景深,请使用以下命令:

cmds.camera('cameraShape1', e=True, dof=False)

因此您的 if 语句 应如下所示:

if(cmds.camera('cameraShape1', q=True, dof=True) == 1):
    cmds.camera('cameraShape1', e=True, dof=False)

关于python - 在 Maya 中使用 Python 引用结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45251046/

相关文章:

python - maya 的宏工具

c++ - 通过 C++ 将自定义形状添加到 Maya 场景

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

Python:查找二维图像直方图的外部峰值

unix - 比较 Unix 脚本中每个单元格的大小

internet-explorer - 为什么实现 IObjectSafety 没有什么不同?

database - 可以在 Groovy 中的 if 语句中为字段赋值导致数据库更新记录

Python子类调用父类的方法

python - 无法在 Windows 上安装正确版本的 mysql(8.0.13)

python - Apache 与扭曲