Reusing token names but giving them different contexts

I have two different token definitions that will resolve to the same thing but have different contexts:

        type: str
        shotgun_entity_type: Shot
        shotgun_field_name: sg_sequence.Sequence.sg_sequence_number

        type: str
        shotgun_entity_type: Sequence
        shotgun_field_name: sg_sequence_number

It’s annoying to have to have two different definitions that are nearly the same. Is there a way to define just one token but have it contextually switch?
I’ve seen the use of the alias attribute in the documentation but I’m not sure if it would work in this case.

Any suggestions?


Hi @StarkRavenSimone ,

I think that you can resolve this, by looking at the core hook. In case the “Entity” of your context is a Shot, you could add it’s sequence to the “additional_entities” list.

This way you can get rid of your first key-definition (Shot, sg_sequence.Sequence…).




The code indicates that the hook is deprecated.
I don’t follow how this is used. Can you give an example of what sort of situation this is useful in?


1 Like

It’s been a while since I used this myself, but I looked it up and found an example.
You may implement it like like this:

class ContextAdditionalEntities(Hook):
    def execute(self, **kwargs):
        val = {"entity_types_in_path": [], "entity_fields_on_task": ["entity.Shot.sg_sequence.Sequence"]}
        return val

This should add a Sequence entity to your contexts in Shotgun Desktop if you have a Shot context. And that hopefully makes your templates resolvable using sequence_number instead of shot_sequence_number.