Optional text field in Maya's "File Open" and "File Save"

Hi all!

I’m trying to add to the File Open and File Save a custom UI element for an optional_field I already defined into the templates.yml.

More specifically what I want to obtain is:

  1. customize the UI of the File Save allowing the user to manually enter an extra value for the optional_field, and than use it in the saving process, so the saved file would be like: name_defined_by_template[_optional_field].ma only if the user do specify the optional_field, otherwise the name would stick to the basic pipeline template, so would be like name_defined_by_template.ma

  2. customize the UI of the File Open allowing the user to manually select from a list (like the one for the File Type) the already present optional_field(s) for the actual context.
    image
    This is only an idea of how to implement the UI. What I need is to be able to open the project files with the optional_field in the last part of the name.

Now I’m trying to add the UI field in File Save window taking over config/hooks/tk-multi-workfiles2/scene_operation_tk-maya.py but no luck.

Do anyone have any idea on how to proceed?

Best regards

Heya!

For an edit like that I don’t think you’ll be able to do it completely via the hooks. Would be great if there was hook functionality to add things like this. But speaking under correction you’ll likely need to take over the entire tk-multi-workfiles2 app and edit the source code.

Depending on your setup you’ll do this via the app_locations.yml. Either pointing to a local OS path, git or SG field. (Let me know if you need help with this setup and I’ll gladly assist)

Once you have control over the app you’ll need to edit the ui files.

This is the compiled Python ui file: tk-multi-workfiles2/python/tk_multi_workfiles/ui/file_save_form.py at master · shotgunsoftware/tk-multi-workfiles2 · GitHub

I do not recommend editing it like this though. Ideally you’d edit the .UI file here: tk-multi-workfiles2/resources/file_save_form.ui at master · shotgunsoftware/tk-multi-workfiles2 · GitHub with something like QT designer. Then re-compile back to a python file and replace the file_save_form.py with your edit.

From there you’d probably just need to splice in your logic with taking the extra template field into account.

Also word of caution, if you add an extra field and your naming convention allows for underscores in the key names, you can run into issues with where to split the optional field.

eg:

{Task}_{Asset}[_{OptionalName}].ma

resolved to:

Case 1 : My_Task_Cool_Asset.ma
Case 2: My_Task_Cool_Asset_Heavy.ma

the template resolution will likely do something like this:
Case 1: OptionalName = Asset
Case 2: OptionalName = Heavy

It cannot split correctly as technically now your asset name also matches the criteria for being an optional name if no optional name is preset. This will be a huge pain - Ask me how I know.

Possible solves to this:

  • Prevent underscores in key names so underscores are always a clean separator
  • Use a double underscore or similar to split your optional key name. eg: {Task}_{Asset}[__{OptionalName}].ma

Best of luck,
Shout if I can help with anything else / go into specifics !

Justin

1 Like

Hi @Justin_Pedersen , Thank you very much for your great, complete and kind reply! You are sharing great knowledge here.

I owe you a big apology for replying so late, this message remained stuck in its text area a while, because I wanted to find the time to make some tests about this workflow before replying.

I was on this path more or less, I also had an approach with the QTdesigner, so your answer gave me the mental tools to understand all the workflow deeper.

At the moment the priorities of the project have changed, so I’m focusing on the development on another part of the pipeline, but as soon as I will have the possibility to come back on this subject, I will, and I’ll probably ask you for help. Hoping you will have the time to respond.

Again, thank you very much!

1 Like