You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/2.0/reference.md
+125Lines changed: 125 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -528,6 +528,131 @@ PYTHONPATH = [
528
528
]
529
529
```
530
530
531
+
<br>
532
+
533
+
## Project Template API
534
+
535
+
The vast majority of data managed by Avalon is stored as files on disk, and every file has a path. The path is an integral part of any production and requires fine-grained control.
536
+
537
+
Avalon provides this control in the form of `templates`.
538
+
539
+
A template is a string of `{placeholders}`, each placeholder representing some data.
Viola, a drastically different directory layout, with identical data and code to process it. Notice how this templates includes reference to `c:\` which not only asserts a particular operating system (Windows) but also leaves no room for an alternative "root". See [Root Template](#root-template) below for an example of how to overcome this limitation.
568
+
569
+
This is how Avalon works.
570
+
571
+
In this way, you can establish *convention* at a high-level whilst still remaning *specific* in places where you need to either read from or write to disk. More importantly, this is the aspect which allows Avalon to not make assumptions about your directory layout; it is up to you to write this template.
572
+
573
+
Having said that, though Avalon doesn't make assumptions about *where* data is written, it *does* make assumptions on the types of data written - referred to as the Avalon Object Model - and your directory layout must accommodate for these types at minimum.
574
+
575
+
- See [Object Model](#object-model) for a high-level overview of these types
576
+
577
+
For any project, Avalon assumes a `work` template to be available in your [Project Configuration](#project-configuration-api). This template is used to generate the initial directory layout for your work-in-progress files.
578
+
579
+
The layout and ordering of placeholders in this template is within your control, and these are the ones available to you.
580
+
581
+
```json
582
+
{
583
+
"root": "Currently registered root, e.g. 'c:/projects'",
584
+
"project": "Current project, e.g. 'hulk'",
585
+
"silo": "Current silo, e.g. 'assets', 'film', 'episodes'",
- See [Project Configuration API](#project-configuration-api) for more.
600
+
601
+
### Template Access
602
+
603
+
Templates are generally stored in your [project configuration](#project-configuration-api).
604
+
605
+
```python
606
+
# Untested
607
+
from avalon import io
608
+
project = io.find_one({"type": "project"})
609
+
template = project["config"]["template"]["work"]
610
+
```
611
+
612
+
### Root Template
613
+
614
+
Every path has a "root"; the first part of a path.
615
+
616
+
```
617
+
c:\
618
+
/root
619
+
/projects/
620
+
```
621
+
622
+
When a template includes a root explicitly, like any of the above, then a template is limited to (1) a particular platform and (2) a particular mount on that platform.
623
+
624
+
For example, if your studio is exclusively on Windows and all share the drive `z:\`, then it is safe to embed this into your template.
625
+
626
+
```python
627
+
template ="z:/projects/{project}/{asset}/..."
628
+
```
629
+
630
+
However, when there are multiple operating systems and/or multiple mount points - e.g. `z:\` on some machines and and `x:\` on others - then the above template no longer works.
631
+
632
+
To work around this, Avalon provides the idea of a "root" directory.
633
+
634
+
```python
635
+
# Windows box, from our London branch
636
+
from avalon import api
637
+
api.register_root(r"c:\projects")
638
+
```
639
+
640
+
At run-time, a root directory is registered relative your platform and mount point, such that your template can look like..
641
+
642
+
```python
643
+
template ="{root}/{project}{asset}..."
644
+
```
645
+
646
+
Such that, on another platform or machine, the root registration can change to account for a differing root.
647
+
648
+
```python
649
+
# Linux box, in LA
650
+
from avalon import api
651
+
api.register_root("/mnt/projects")
652
+
```
653
+
654
+
As a result, your folder creation and publishing code can remain as-is, whilst assets are being read and written all over the place.
0 commit comments