0

How do I add a hotkey shortcut to Nuke for Shotgun Save As?

Our artists are allergic to menus! We would really like to be able to add a keyboard shortcut (hotkey) to allow them to activate the "Shotgun Save As..." menu. In fact, we'd love to override the default hotkey for "Save As..." in Nuke so it activates the "Shotgun Save As..." menu item instead. 

We'd also love to override the default Write Node hotkey so it adds a Shotgun Write Node (Mono Dpx [Shotgun]).

How can we do this with Toolkit?

 

댓글 2개

  • 0
    Avatar
    KP

    It's great to make your artists' lives easier. And yes, you can use the engine_init core hook to add shortcuts to the Shotgun Toolkit menu items in Nuke. You should ensure the hotkey isn't currently being used for another menu item (which can cause weirdness and instability). But if you know a hotkey already exists for something and you want to re-assign it, you can do that fairly easily.

    The engine_init core hook is run every time any engine is done initializing. To customize it, copy the default hook from your studio install directory to your project core hooks directory which will look something like this:

    $ cp /path/to/sgtk/software/shotgun/studio/install/core/hooks/engine_init.py /path/to/sgtk/software/shotgun/<project_name>/core/hooks/engine_init.py

     

    Then open up the copied file to edit it. In the execute() method, we'll need to first check that the Nuke engine is the one calling this hook, and if so, we can proceed with our code. 

    from tank import Hook
    import os
    class EngineInit(Hook):
    def execute(self, engine, **kwargs):
    """
    Gets executed when a Toolkit engine has fully initialized.
    At this point, all applications and frameworks have been loaded,
    and the engine is fully operational.

    :param engine: The current engine being initialised
    """
    if engine.name == 'tk-nuke':
            self.__override_nuke_shortcuts(engine)
                
        def __override_nuke_shortcuts(self, engine):
            """
            Override various shortcut keys in Nuke to run our own commands
            instead

    :param engine: The current engine
            """
    import nuke
    if not nuke.env.get("gui"):
    # not running in interactive mode so don't have menus or shortcuts!
    return

    # remove default hotkey from File > Save As...
    # NOTE: Nuke 9 renamed this menu to "Save Comp As..." :/
    file_menu = nuke.menu("Nuke").findItem("File")
    save_as_item = file_menu.findItem("Save As...")
    save_as_item.setShortcut("")
    engine.log_debug("removed default hot key for File > Save As...")

    # add new hot key for Shotgun > Shotgun Save As...
    sg_menu = nuke.menu("Nuke").findItem("Shotgun")
    if sg_menu:
    sg_save_as_item = sg_menu.findItem("Shotgun Save As...")
    if sg_save_as_item:
    sg_save_as_item.setShortcut("Ctrl+Shift+S")
    engine.log_debug("Set hot key for SG Save As...")

    # remove default hotkey for write node
    write_node_item = nuke.menu('Nodes').findItem("Image/Write")
    write_node_item.setShortcut("")
    engine.log_debug("removed default hot key for node Image/Write...")

    # add new hot key for Shotgun Mono Dpx Write Node
    sg_write_node_item = nuke.menu('Nodes').findItem("Shotgun/Mono Dpx [Shotgun]")
    if sg_write_node_item:
    sg_write_node_item.setShortcut("w")
    engine.log_debug("Set hot key for SG write node")

     

    If you'd like to learn more about how these work, there's more info about Core Hooks in our docs. 

    Hope this makes your artists happier and less allergic! 

  • 0
    Avatar
    Joan Azpeitia

    Hi KP,

     

    Thanks for helping.

    I am trying your example but I am doing something wrong, I think just at the begging when doing the

    if engine.name == 'tk-nuke':


    I am getting this error,

    TankError: No engine is currently running! Run start_engine instead.

    [ERROR tk-multi-workfiles2] Failed to change the work area to Shot Shot_01!

    Traceback (most recent call last):

    File "Y:\_PLUGINGS\Shotgun\TheKillTeam\install\app_store\tk-multi-workfiles2\v0.9.9\python\tk_multi_workfiles\actions\open_file_action.py", line 115, in _do_copy_and_open

    FileAction.change_context(new_ctx)

    File "Y:\_PLUGINGS\Shotgun\TheKillTeam\install\app_store\tk-multi-workfiles2\v0.9.9\python\tk_multi_workfiles\actions\file_action.py", line 123, in change_context

    raise TankError("Failed to change work area - %s" % e)

    TankError: Failed to change work area - No engine is currently running! Run start_engine instead.

     

     

    I tried with this method to get the engine name,

     

    engine = sgtk.platform.current_engine()

     

    Which gives me this,

     

    <Sgtk Engine 0x58a1ae48: tk-nuke, env: shot>

     

    But don't know how to slice tk-nuke from this string.

     

    Any idea of what I am doing wrong?

     

    Thanks,

     

    Joan

댓글을 남기려면 로그인하세요.