Created
January 20, 2025 20:23
-
-
Save BigRoy/f66b4acf8539c7cec6b94e5204e4a591 to your computer and use it in GitHub Desktop.
AYON Fusion integration imprint container to all loaders loading a published filepath that is currently not linked
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Fix unlinked/unmanaged loaders in Fusion to get managed by AYON as intended.""" | |
from pathlib import Path | |
from typing import List | |
import time | |
import logging | |
import ayon_api | |
from ayon_core.pipeline import get_current_project_name | |
log = logging.getLogger("AYON fix links") | |
# Get a mapping from all representations' paths to the representation | |
s = time.time() | |
project_name = get_current_project_name() | |
representations = ayon_api.get_representations(project_name, fields={"attrib.path", "id", "versionId"}) | |
path_to_repre = {} | |
for repre in representations: | |
path = repre["attrib"]["path"] | |
path_to_repre[Path(path)] = repre | |
e = time.time() | |
print(f"{e-s:0.04f}s time taken to get all project representations") | |
comp = fusion.GetCurrentComp() | |
def get_loader_path(tool) -> List[Path]: | |
"""Return the clip paths from Loader""" | |
clips = tool.GetAttrs()['TOOLST_Clip_Name'] | |
return [Path(path) for path in clips.values()] | |
for tool in comp.GetToolList(False, "Loader").values(): | |
existing_data = tool.GetData("avalon") | |
for path in get_loader_path(tool): | |
if path not in path_to_repre: | |
log.warning(f"No match found for '{tool.Name}' path: {path}") | |
continue | |
representation = path_to_repre[path] | |
# Already ok | |
if existing_data and existing_data.get("representation") == representation["id"]: | |
break | |
version = ayon_api.get_version_by_id(project_name, version_id=representation["versionId"]) | |
product = ayon_api.get_product_by_id(project_name, product_id=version["productId"]) | |
folder = ayon_api.get_folder_by_id(project_name, folder_id=product["folderId"]) | |
data = { | |
"project_name": project_name, | |
"name": product["name"], | |
"loader": "FusionLoadSequence", | |
"id": "pyblish.avalon.container", | |
"representation": representation["id"], | |
"schema": "openpype:container-2.0", | |
"namespace": folder["name"] | |
} | |
tool.SetData("avalon", data) | |
print(f"Fixed {tool.Name: <25} {folder['name']} > {product['name']}") | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment