I just wanted to share a possible solution/hack for this:
First, it is not a very elegant way, and it does not seem to work for every sg app.
The main idea behind this is to use the “Additional Entities” on the context,
what gets used when resolving any templates:
In the context_change hook (post_context_change), I extracted the current engine.name,
queried a shotgun Software entity with this engine name and put this entity in the
“Additional Entities” list into the current given context.
When starting any software, now a software entity with the correct current engine.name
is automatically available in the “Additional Entities”
In the templates.yml I created a key like this:
and a test template like this:
- Running this python code in maya, i get my desired path:
tk = engine.sgtk
context = engine.context
template = tk.templates['shot_work_dcc']
fields = context.as_template_fields(template)
path = template.apply_fields(fields)
So, this could be a way to extract data from any entity in SG for the templates, even if it is not linked to anything.
Unfortunately, it did not work for the tk-multi-workfiles2 app,
the folders got created correctly, but then failed to validate the context here:
because “Software” is missing:
…could not be populated by context ‘animation, Shot sh001’ because the context does not contain a shotgun entity of type ‘Software’!
Which kind of makes sense, since there is no context change (and therefore a “Software” entity available via the context change hook) before it gets queried…
I will investigate further into this, maybe some custom minor code changes
the the core api / context.py could help here…
hopefully there will be an “official” solution to this in the near future since it would really
help with templating maintenance…