如何在 Maya 中添加用于启动 Toolki 应用的工具架按钮?

在 Maya 中添加一个用于启动 Maya 的 Toolkit 应用的工具架按钮是一项非常简单的操作。以下示例显示了如何添加自定义工具架按钮,以便打开加载器应用。(请注意,这里假定当前已在 Maya 中启用了 Toolkit,但系统不会对 Toolkit 进行引导)。

在 Maya 中打开脚本编辑器并粘贴以下 Python 代码: 

import maya.cmds as cmds 

# The internal Toolkit app name
tk_app = "tk-multi-loader2"

# The public function that opens the app dialog. This function is located in the app's 
# app.py file in the top directory (eg. install/apps/app_store/tk-multi-loader2/app.py.
# The name of this function varies from app to app, but is generally easy to determine by
# looking at the code. 
call_func = "open_publish"

try: 
    import sgtk

    # get the current engine (e.g. tk-maya) 
    current_engine = sgtk.platform.current_engine() 
    if not current_engine: 
        cmds.error("Shotgun integration is not available!") 

    # find the current instance of the app: 
    app = current_engine.apps.get(tk_app) 
    if not app: 
        cmds.error("The Toolkit app '%s' is not available!" % tk_app) 

    # call the public method on the app to show the dialog: 
    app_open_func = getattr(app, call_func)
    app_open_func()
except Exception, e: 
    msg = "Unable to launch Toolkit app '%s': %s" % (tk_app, e)
    cmds.confirmDialog(title="Toolkit Error", icon="critical", message=msg)
    cmds.error(msg) 

选择此代码并将其拖动到自定义工具架。请参见 Maya 文档以了解有关如何使用自定义工具架按钮的详细信息

您应该可以使用此代码示例启动在 Maya 中启用的任何 Toolkit 应用,方法是修改顶部的 tk_appcall_func 变量。

 

 

关注

0 评论

登录写评论。