【问题标题】:maya.cmds Dialog to end scriptmaya.cmds 对话框结束脚本
【发布时间】:2019-09-07 20:51:24
【问题描述】:

一旦没有找到属性,我想结束整个脚本。目前,我有以下代码。我显示一个对话框并使用sys.exit() 结束脚本,但我想知道是否有一个 cmds 对话框可以在没有sys.exit() 的情况下自动为您执行此操作,

def check_attr(attr):
    if not cmds.select(cmds.ls(attr)):
         cmds.confirmDialog(title= 'Attribute not found   ', message = attr+' attribute was not found', button =['OK'])
         sys.exit()

我的问题:是否存在停止脚本的 cmds...对话框?

【问题讨论】:

  • 你的意思是像: cmds.error() 吗?并且没有错误的对话框预设,但你可以包装你的。
  • 你也可以在 Maya 中使用 PySide2 或 PyQt5,这样你就可以使用 QMessageBox :stackoverflow.com/questions/40227047/…
  • @DrWeeny 我的意思是类似 cmds.exitDialog("error message") 它只是退出,但我认为对话框没有那个功能

标签: python maya pymel


【解决方案1】:

由于您使用的是函数,最简单的方法是在 if 条件中使用 return,这样它就不会继续函数的其余部分:

def check_attr(attr):
    if not cmds.select(cmds.ls(attr)):
         cmds.confirmDialog(title= 'Attribute not found   ', message = attr+' attribute was not found', button =['OK'])
         return

    print "Continuing script"


check_attr("someAttr")

您也可以使用OpenMaya.MGlobal.displayError 将其显示在 Maya 的任务栏中:

import maya.OpenMaya as OpenMaya


def check_attr(attr):
    if not cmds.select(cmds.ls(attr)):
         OpenMaya.MGlobal.displayError(attr + ' attribute was not found')
         return

    print "Continuing script"


check_attr("attr")

虽然OpenMaya.MGlobal.displayError 只是显示一个错误,但要小心,它不会像cmds.error 那样停止执行。你也可以使用cmds.error,但是我发现它在任务栏中吐出的错误可读性要差很多。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    相关资源
    最近更新 更多