How do I add a shelf button to launch a Toolkit app in Maya?

Adding a shelf button in Maya to launch Toolkit apps in Maya is pretty straightforward. Here is an example of how to add a custom shelf button that opens the Loader app. (Note that this assumes Toolkit is currently enabled in your Maya session, this does not bootstrap Toolkit).

Open your Script Editor in Maya and paste in the following Python code: 

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) 

Select this code and drag it on to your custom shelf. See the Maya docs for more info on how to work with custom shelf buttons

You should be able to use this code example to launch any Toolkit apps that are enabled in Maya by modifying the tk_app and call_func variables at the top.

 

 

Follow

3 Comments

  • 0
    Avatar
    lozo vfx

    I was trying to launch the tk-multi-publish2 app  but I can't seem to find the correct function call to show the dialog window.  Any hints?

  • 0
    Avatar
    lozo vfx

    Here 2 options  Philip Scadding sent me via support.

    The first one worked perfectly.  Thanks!

     

     

    import maya.cmds as cmds 
    
    # The internal Toolkit app name
    tk_app = "tk-multi-publish2"
    
    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:
        tk_multi_publish2 = app.import_module("tk_multi_publish2")
    
        # make the util methods available via the app instance
        app._util = tk_multi_publish2.util
    
        # make the base plugins available via the app
        app._base_hooks = tk_multi_publish2.base_hooks
    
    
        tk_multi_publish2.show_dialog(app)
    
    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) 
    

    or

    import maya.cmds as cmds 
    
    # The internal Toolkit app name
    tk_app = "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: 
        command = current_engine.commands.get(tk_app) 
        if not app: 
            cmds.error("The Toolkit app '%s' is not available!" % tk_app) 
    
        current_engine.commands[tk_app]['callback']()
    
    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) 
    
  • 0
    Avatar
    Stuart Wells

    Hi lozo vfx

    Thanks for these scripts there great, Iv been trying to make shotgun a bit quicker to use and shelf buttons would be great. Is there any chance i could get a script for the File Save as well? That would be great thanks. 

Please sign in to leave a comment.