-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolve_paths_using_template_data.py
54 lines (42 loc) · 1.39 KB
/
resolve_paths_using_template_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
Get Template data and resolve work directory template.
"""
import ayon_api
from ayon_core.pipeline import (
Anatomy,
get_current_context,
get_current_host_name,
)
from ayon_core.pipeline.template_data import get_template_data
from ayon_core.lib import StringTemplate
# Get Current Context
host_name = get_current_host_name()
context = get_current_context()
project_name = context["project_name"]
folder_path = context["folder_path"]
task_name = context["task_name"]
# Get Entities
project_entity = ayon_api.get_project(project_name)
folder_entity = ayon_api.get_folder_by_path(project_name, folder_path)
task_entity = ayon_api.get_task_by_name(
project_name, folder_entity["id"], task_name
)
# Get Template Data
template_data = get_template_data(
project_entity, folder_entity, task_entity, host_name
)
# Add Roots to template data
anatomy = Anatomy(project_name, project_entity=project_entity)
template_data["root"] = anatomy.roots
# Resolve Path
work_dir = anatomy.templates["work"]["default"]["directory"]
work_dir = StringTemplate.format_template(work_dir, template_data)
print(work_dir)
# -------------------------------
# Alternatively, for this particular example,
# we already have a function to retrieve resolved work dir
from ayon_core.pipeline.workfile import get_workdir
work_dir = get_workdir(
project_entity, folder_entity, task_entity, host_name
)
print(work_dir)