Workfiles tab order

You can do either, but it does get a bit messy here. Obviously it’s nicer if it is defined in the yml file so all your settings are kept together. But to do this you would need to pass the settings as a string args to the hook. Each : after the hook name denotes args. So you could, in theory, pass the settings through as string args.

Here is an example
In the yaml file I’m passing two parameters through to my custom hook called example_template_hook, though the hook can be renamed to something else, it just needs to live in the .../config/core/hooks/ directory).
Each tab is passed as a separate parameter so that we can easily separate them in the hook, Notice the : character after the hierarchy; [step] of the first tab settings.
Since we are passing each parameter as a string and we don’t want the yaml parser to interpret our string as a yaml just yet, I’ve temporarily switched all the : for ; characters. If we didn’t do this then each : it encountered would be treated as a separate parameter to pass to the hook.
The > character at the beginning allows us to provide a multiline value.

settings.tk-multi-workfiles2.launch_at_startup:
  launch_at_startup: true
  entities: >
    hook:example_template_hook:- caption; Shots
      entity_type; Shot
      filters;
      hierarchy; [sg_sequence, code]
      sub_hierarchy;
        entity_type; Task
        filters;
        link_field; entity
        hierarchy; [step]:
    - caption; Assets
      entity_type; Asset
      hierarchy; [sg_asset_type, code]
      filters;
      sub_hierarchy;
        entity_type; Task
        filters;
        link_field; entity
        hierarchy; [step]
  location: "@apps.tk-multi-workfiles2.location"

Then in the hook we can resolve each tab parameter and then return them in what ever order we like:

from tank import Hook
from tank_vendor import ruamel_yaml

class ExampleTemplateHook(Hook):

    def execute(self, setting, bundle_obj, extra_params, **kwargs):
        
        # grab each tab from the separate params, and resolve them
        shot_tab = self.resolve_yaml_string(extra_params[0])
        asset_tab = self.resolve_yaml_string(extra_params[1])

        # now combine the tabs in what ever order we like
        all_tabs = asset_tab + shot_tab
        self.logger.info("tabs: %s" % all_tabs)

        return all_tabs

    def resolve_yaml_string(self, yaml_string):
        # resolve the string into actual python object using yaml
        # first we need to substitute the ; for the correct :
        yaml_string = yaml_string.replace(";", ":")
        return ruamel_yaml.load(yaml_string)
2 Likes