1

Ambiguous template issue caused by '_'

Hi guys,

I'm struggling a little bit with our asset template definitions. Our token separators are '_' and we also allow the use of '_' in the asset names.

So given the template attached, a call to template.get_fields for a model named 'tk_asset_01_mod_lo' leads to the following error message:

Template <Sgtk TemplateString asset_model_name: {Asset}_{Step}_[{name}_]{lod}>: Ambiguous values found for key 'Asset' could be any of: 'tk', 'tk_asset', 'tk_asset_01'

The first workaround I found to make this work is to force the length of the Step token to 3, as our steps use currently 3 char names . An other way is to add an exclusion list to the Step token. What bothers me doing that is the Step token is linked to Shotgun entity and I don't want to duplicate the list of possible values nor force the length to a value that may change when I add a new Step to our pipeline.

Is there another more elegant solution?

Why not allow the template system to check those values from Shotgun using a new template option. Directly using Shotgun will slowdown the templates resolution so maybe we can use the path_cache for that purpose.

Meanwhile I will limit the length of the token but I would really like to use another solution.

Thanks




asset_name_template.yml

3 comments

  • 0
    Avatar
    Ryan Mayeda

    Hi Julien.

    I finally got a chance to give this a try, and I think you can do what you need here by using filters on your template keys.  I think this is better than using the length restriction, but you can be the judge on if it's elegant enough.  :)

    I basically used the 'filter_by: alpha' option for the {Step}, {name}, and {lod} keys.  This way, there's no ambiguity over where the '01' goes.  I have attached my updated templates file, and below are the results I get:

    >>> template = tk.templates['asset_model_name']
    >>> template.get_fields('tk_asset_01_mod_lo')
    {'Step': 'mod', 'Asset': 'tk_asset_01', 'lod': 'lo'}
    >>> template.get_fields('tk_asset_01_mod_test_lo')
    {'Step': 'mod', 'Asset': 'tk_asset_01', 'lod': 'lo', 'name': 'test'}

    With this option, you're free to name Steps however you want, and you don't need to replicate your Steps from Shotgun as choices in your template configuration.  One big assumption this makes is that your Steps don't have non-alpha characters in it (i.e. there are no numbers).  If you use 'filter_by: alphanumeric' instead, the result will be this, which I don't think is right:

    >>> template = tk.templates['asset_model_name']
    >>> template.get_fields('tk_asset_01_mod_lo')
    {'Step': '01', 'Asset': 'tk_asset', 'lod': 'lo', 'name': 'mod'}

    The alphanumeric option will cause it to prioritize the '01' token over the optional {name} token.  Hopefully this is ok for you!

    Anyhow, give this a try and see if it works on your side.  I'm also interested to hear if it works for other important use cases in your pipeline.

    Ryan.

  • 0
    Avatar
    Julien Dubuisson

    Hi Ryan,

    I can confirm you that it's perfectly working.

    Thanks

  • 0
    Avatar
    Ryan Mayeda

    Great, glad to hear it!

Please sign in to leave a comment.