photoshop load plugins are expecting representation context

This commit is contained in:
Jakub Trllo 2024-02-26 17:53:47 +01:00
parent d790d2e411
commit 3c67c4fdd0
4 changed files with 26 additions and 21 deletions

View file

@ -224,23 +224,23 @@ class ImageLoader(load.LoaderPlugin):
self.__class__.__name__
)
def update(self, container, representation):
def update(self, container, context):
layer = container.pop("layer")
repre_doc = context["representation"]
with photoshop.maintained_selection():
stub.replace_smart_object(
layer, get_representation_path(representation)
layer, get_representation_path(repre_doc)
)
stub.imprint(
layer, {"representation": str(representation["_id"])}
layer, {"representation": str(repre_doc["_id"])}
)
def remove(self, container):
container["layer"].Delete()
def switch(self, container, representation):
self.update(container, representation)
def switch(self, container, context):
self.update(container, context)
```
For easier debugging of Javascript:
https://community.adobe.com/t5/download-install/adobe-extension-debuger-problem/td-p/10911704?page=1

View file

@ -36,13 +36,13 @@ class ImageLoader(photoshop.PhotoshopLoader):
self.__class__.__name__
)
def update(self, container, representation):
def update(self, container, context):
""" Switch asset or change version """
stub = self.get_stub()
layer = container.pop("layer")
context = representation.get("context", {})
repre_doc = context["representation"]
namespace_from_container = re.sub(r'_\d{3}$', '',
container["namespace"])
@ -55,14 +55,14 @@ class ImageLoader(photoshop.PhotoshopLoader):
else: # switching version - keep same name
layer_name = container["namespace"]
path = get_representation_path(representation)
path = get_representation_path(repre_doc)
with photoshop.maintained_selection():
stub.replace_smart_object(
layer, path, layer_name
)
stub.imprint(
layer.id, {"representation": str(representation["_id"])}
layer.id, {"representation": str(repre_doc["_id"])}
)
def remove(self, container):
@ -77,8 +77,8 @@ class ImageLoader(photoshop.PhotoshopLoader):
stub.imprint(layer.id, {})
stub.delete_layer(layer.id)
def switch(self, container, representation):
self.update(container, representation)
def switch(self, container, context):
self.update(container, context)
def import_layer(self, file_name, layer_name, stub):
return stub.import_smart_object(file_name, layer_name)

View file

@ -86,7 +86,7 @@ class ImageFromSequenceLoader(photoshop.PhotoshopLoader):
)
]
def update(self, container, representation):
def update(self, container, context):
"""No update possible, not containerized."""
pass

View file

@ -37,32 +37,37 @@ class ReferenceLoader(photoshop.PhotoshopLoader):
self.__class__.__name__
)
def update(self, container, representation):
def update(self, container, context):
""" Switch asset or change version """
stub = self.get_stub()
layer = container.pop("layer")
context = representation.get("context", {})
asset_doc = context["asset"]
subset_doc = context["subset"]
repre_doc = context["representation"]
folder_name = asset_doc["name"]
product_name = subset_doc["name"]
namespace_from_container = re.sub(r'_\d{3}$', '',
container["namespace"])
layer_name = "{}_{}".format(context["asset"], context["subset"])
layer_name = "{}_{}".format(folder_name, product_name)
# switching assets
if namespace_from_container != layer_name:
layer_name = get_unique_layer_name(
stub.get_layers(), context["asset"], context["subset"]
stub.get_layers(), folder_name, product_name
)
else: # switching version - keep same name
layer_name = container["namespace"]
path = get_representation_path(representation)
path = get_representation_path(repre_doc)
with photoshop.maintained_selection():
stub.replace_smart_object(
layer, path, layer_name
)
stub.imprint(
layer.id, {"representation": str(representation["_id"])}
layer.id, {"representation": str(repre_doc["_id"])}
)
def remove(self, container):
@ -76,8 +81,8 @@ class ReferenceLoader(photoshop.PhotoshopLoader):
stub.imprint(layer.id, {})
stub.delete_layer(layer.id)
def switch(self, container, representation):
self.update(container, representation)
def switch(self, container, context):
self.update(container, context)
def import_layer(self, file_name, layer_name, stub):
return stub.import_smart_object(