Using subset TemplateKey in Workfiles

We have a client that would like to insert the artist initials in the filename for all workfiles and publishes. I know we can create a TemplateKey that looks roughly something like this:

    user_initials:
        shotgun_entity_type: HumanUser
        shotgun_field_name: name
        type: str
        # Spaces are replaced with `-` by TK
        subset: '([A-Z])[a-z]*-([A-Z])[a-z]*'

And there’s similar docs about using subset here.

And a template like so:

    photoshop_asset_work:
        definition: '@asset_root/work/photoshop/{Asset}_{Step}_{user_initials}_v{version}.psd'

For tk-multi-workfiles2, this works fine when saving files. But when reading them back to open files, this will fall over because the {user_initials} in the filename is now two characters (eg KP) and doesn’t match the template key definition anymore - thus generating a template validation error.

The workaround I’m currently using (and have used in similar circumstances with other studios), is relying on storing this information in a separate field in Shotgun as HumanUser.sg_initials and defining the key with:

    user_initials:
        shotgun_entity_type: HumanUser
        shotgun_field_name: sg_initials
        type: str
        filter_by: "^[A-Za-z]{2}$"

This works fine for both opening and saving files. Is there a more elegant way to not have to store and maintain this extra data in Shotgun as a separate data point? Feels like there should be a way… so maybe I’m missing something?

Any ideas or suggestions from others who may be doing something similar are welcome!

cheers,
kp

2 Likes

Hey KP –

I’m going to test this out and see if I get what you’re getting, but first:

  • Are you saying it doesn’t work the second time around because it’s now running that regex against “KP” instead of “Kevin-Porterfield”, so it doesn’t match?
  • If so, I wonder if you can just tweak your regex so it works in both cases. What if you did this:
        subset: '([A-Z])[a-z\-]*([A-Z])[a-z]*'

The only difference from what you have is that the middle dash becomes optional along with all the lowercase letters, so it should match both KP and Kevin-Porterfield. Still a hack, but one with a much smaller footprint.

2 Likes

Thanks Tannaz!

This would probably simplify things. And actually I could update it to something even a little more flexible which will take care of some possible anomalies like not capitalizing the first letter of names and other garbage:

        subset: '([A-Za-z])\w*\W*([A-Za-z]).*'

However, the subset functionality falls victim to a bug in tk-multi-workfiles2 which I have previously submitted a PR for here https://github.com/shotgunsoftware/tk-multi-workfiles2/pull/89. (@philip.scadding saw my initial PR for this a few months back I think. I had to resubmit it because we inadvertently blew away the initial branch we submitted it from).

When the app is constructing the File Keys to use for matching work and publish files to determine the next version number, it uses the raw value of the template key (“Kevin Porterfield”) instead of the processed value (“KP”). This manifests itself by not incrementing the next available version number correctly which can cause data loss.

So for now I’ll use the regex but will use it with our forked version of the app until the PR gets reviewed and hopefully merged.

Thanks!