Added Loader Hooks to switch_container

This commit is contained in:
Petr Kalis 2025-04-04 17:20:09 +02:00
parent f609d2f5c4
commit 3a2d831ca6
2 changed files with 31 additions and 4 deletions

View file

@ -632,15 +632,22 @@ def update_container(container, version=-1, hooks_by_identifier=None):
return update_return
def switch_container(container, representation, loader_plugin=None):
def switch_container(
container,
representation,
loader_plugin=None,
hooks_by_identifier=None
):
"""Switch a container to representation
Args:
container (dict): container information
representation (dict): representation entity
loader_plugin (LoaderPlugin)
hooks_by_identifier (dict): {"pre": [PreHookPlugin1], "post":[]}
Returns:
function call
return from function call
"""
from ayon_core.pipeline import get_current_project_name
@ -679,7 +686,21 @@ def switch_container(container, representation, loader_plugin=None):
loader = loader_plugin(context)
return loader.switch(container, context)
loader_identifier = get_loader_identifier(loader)
hooks = hooks_by_identifier.get(loader_identifier, {})
for hook_plugin in hooks.get("pre", []):
hook_plugin.switch(
context,
container
)
switch_return = loader.switch(container, context)
for hook_plugin in hooks.get("post", []):
hook_plugin.switch(
context,
container
)
return switch_return
def _fix_representation_context_compatibility(repre_context):

View file

@ -1339,8 +1339,14 @@ class SwitchAssetDialog(QtWidgets.QDialog):
repre_entity = repres_by_name[container_repre_name]
error = None
hook_loaders_by_id = self._controller.get_hook_loaders_by_identifier()
try:
switch_container(container, repre_entity, loader)
switch_container(
container,
repre_entity,
loader,
hook_loaders_by_id
)
except (
LoaderSwitchNotImplementedError,
IncompatibleLoaderError,