Hi,
I am trying to make sense of the key options inside the templates.yml file.
The option shotgun_entity_type: seems to be a promising solution to the following problem:
Assume the asset field is allowed to contain underscores ‘_’ in it’s name, which can be problematic with the template validation.
Suppose this template definition and it’s evaluation:
>>> my_template.definition
>>> "{Asset}_{shader}_v{version}"
>>> my_template.validate_and_get_fields("my_test_asset_blue_v001")
>>> {"Asset" : "my_test_asset", "Shader" : "blue", "version" : 1 }
# this is correct. The asset "my_test_asset" exists and so does the shader "blue"
We now want to detect files that are not matching this template, with just using the template itself.
>>> my_template.validate_and_get_fields("my_test_asset_blue_some_unpredictableUnderScoreNaming_v001")
>>> {"Asset" : "my_test_asset_blue_some", "Shader" : "unpredictableUnderScoreNaming", "version" : 1 }
# this is not correct / undesired !
# The Asset is miss interpreted to my_test_asset_blue_some
# the Shader is miss interpreted to unpredictableUnderScoreNaming
# my_template.validate("my_test_asset_blue_some_unpredictableUnderScoreNaming_v001") returns True but should be False
(*Note: a work around could include adding more template definitions, composed of other templates. Or a even an extra check for the “Asset” field to be a valid asset in the database. I want to avoid these work-arounds and if possible utilise template definition key options shotgun_entity_type and shotgun_field_name or a more convenient solution when working with fields that allow ‘_’ in general. )
The key options are documented here (The key section):
the templates.yml would contain:
keys:
version:
type: int
format_spec: "03"
Shader:
type: str
Asset:
type: str
shotgun_entity_type: Asset # (?) what does this do ?
shotgun_field_name: code
strings:
my_template:
definition: {Asset}_{shader}_v{version}
1.) How do I use the template key options shotgun_entity_type and
shotgun_field_name correctly ?
Could you give a use case example ?
2.) What could fields that allow for underscores be handled neatly inside inside the templates ?
(*Note: there is also the option to specify a regular expression to valuate filter_by:'^[0-9]{4}_[a-z]{3}$'
, but in the case of handling/ variable multiple underscores for the Asset field, the regex will always output multiple solutions, which in return will make the template fail the validation )
Any help or advice is greatly appreciated.
Kind Regards
Stu