I’m trying to devise a toolkit-friendly way to add a “New File…” menu option to Nuke. The workflow I’m looking to implement is fairly straightforward. When a Shot is new, as in, has never been worked on before, I would like the pipeline to create a stub Nuke script based on a project template. Initially, this needs to have the proper frame range set from the database, Read nodes for all the currently published plates, a Write node, and color configured for the specific shot.
My first thought was to look at making a custom hook for tk-shotgun-folders, but then it occurred to me that this hook most likely will not have access to the nuke Python library. My next step was to look into custom hooks for tk-multi-workfiles2. It looks like I have two possible ways forward.
Copy the code from tk-multi-workfiles2/hooks/scene_operation_tk-nuke.py into {config}/scene_operation_tk-nuke.py, and implement the prepare_new scene operation.
Copy the code from tk-multi-workfiles2/hooks/custom_action.py into {config}/new_action_tk-nuke.py, and write some code to make a new file.
Has anyone done this before, and if so, could you recommend the easiest way forward?
Also, it looks like I need to add, in tk-nuke.yml, in the settings.tk-nuke.shot_step section, another entry under menu_favourites. However, all the documentation mentions here is that you need to specify an app_instance and a caption. There is no easily-discernible way to directly link a Python callable to a menu item, or at least, not that I could see.
I swear I’ve seen this accomplished somewhere before, but my memory is failing me. I’ll consult the rest of the Toolkit hive mind and we’ll report back!
I don’t believe you can use the menu_favourites to set up a new menu name for an instance of a Workfiles2 callback, but I’m not sure you’d want to. With the ideas you discuss above, you’d just have a copy of the File Open UI, under a different name, with slightly different functionality, which I think would be confusing for users.
The File Open UI in Workfiles already has a “New File” button that can be used when there isn’t yet an existing workfile for the selected task. It sounds like you’d just want to modify the functionality of this button, which you can do with hooks.
The hook to modify is the scene_operation_tk-nuke hook. There’s an important distinction to make between actions and operations: Actions, like new_file , version_up , etc. are what the user did to trigger the hook. Operations, like open and reset are code that the hook runs within the DCC.
So, there isn’t a specific operation that corresponds to the new_file action, but reset does run at new file time. However, reset also runs at file open time, so if you modify that operation, you’ll want to make sure to limit your customizations to the new_file action.
To do that, you’ll want to customize the hook like this:
...
elif operation == "reset":
if parent_action == "new_file":
do_custom_stuff()
inserting your custom logic in place of the dummy do_custom_stuff() method above.
Hope that helps! Let me know if you have any other questions.