Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Photoshop: implemented {layer} placeholder in subset template #3591

53 changes: 53 additions & 0 deletions openpype/hosts/photoshop/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

from openpype.pipeline import LoaderPlugin
from .launch_logic import stub
from openpype.pipeline import legacy_io
from openpype.client import get_asset_by_name
from openpype.settings import get_project_settings
from openpype.lib import prepare_template_data
from openpype.lib.profiles_filtering import filter_profiles


def get_unique_layer_name(layers, asset_name, subset_name):
Expand Down Expand Up @@ -33,3 +38,51 @@ class PhotoshopLoader(LoaderPlugin):
@staticmethod
def get_stub():
return stub()


def get_subset_template(family):
"""Get subset template name from Settings"""
project_name = legacy_io.Session["AVALON_PROJECT"]
asset_name = legacy_io.Session["AVALON_ASSET"]
task_name = legacy_io.Session["AVALON_TASK"]

asset_doc = get_asset_by_name(
project_name, asset_name, fields=["data.tasks"]
)
asset_tasks = asset_doc.get("data", {}).get("tasks") or {}
task_info = asset_tasks.get(task_name) or {}
task_type = task_info.get("type")

tools_settings = get_project_settings(project_name)["global"]["tools"]
profiles = tools_settings["creator"]["subset_name_profiles"]
filtering_criteria = {
"families": family,
"hosts": "photoshop",
"tasks": task_name,
"task_types": task_type
}

matching_profile = filter_profiles(profiles, filtering_criteria)
if matching_profile:
return matching_profile["template"]


def get_subset_name_for_multiple(subset_name, subset_template, group,
family, variant):
"""Update subset name with layer information to differentiate multiple

subset_template might contain specific way how to format layer name
({layer},{Layer} or {LAYER}). If subset_template doesn't contain placeholder
at all, fall back to original solution.
"""
if not subset_template or 'layer' not in subset_template.lower():
subset_name += group.name.title().replace(" ", "")
else:
fill_pairs = {
"family": family,
"variant": variant,
"task": legacy_io.Session["AVALON_TASK"],
"layer": group.name
}

return subset_template.format(**prepare_template_data(fill_pairs))
17 changes: 16 additions & 1 deletion openpype/hosts/photoshop/plugins/create/create_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
CreatedInstance,
legacy_io
)
from openpype.hosts.photoshop.api.plugin import (
get_subset_template,
get_subset_name_for_multiple
)


class ImageCreator(Creator):
Expand Down Expand Up @@ -68,7 +72,12 @@ def create(self, subset_name_from_ui, data, pre_create_data):

if creating_multiple_groups:
# concatenate with layer name to differentiate subsets
subset_name += group.name.title().replace(" ", "")
subset_template = get_subset_template(self.family)
subset_name = get_subset_name_for_multiple(subset_name,
subset_template,
group,
self.family,
data["variant"])

if group.long_name:
for directory in group.long_name[::-1]:
Expand Down Expand Up @@ -143,3 +152,9 @@ def _handle_legacy(self, instance_data):
def _clean_highlights(self, stub, item):
return item.replace(stub.PUBLISH_ICON, '').replace(stub.LOADED_ICON,
'')
@classmethod
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 1 blank line, found 0

def get_dynamic_data(
cls, variant, task_name, asset_id, project_name, host_name
):
"""Called by UI, empty value for layer must be provided."""
return {"layer": ""}
Copy link
Member

@iLLiCiTiT iLLiCiTiT Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe simpler variant would be to return formattings placeholder and fill it in create?

def get_dynamic_data(cls, *args, **kwargs):
    return {"layer": "{layer}"}

And in create:

layer_name = ""
if len(groups) > 1:
    layer_name = group.name
layer_fill = prepare_template_data({"layer": layer_name})
subset_name = subset_name.format(**layer_fill)

You don't need to duplicate code with get_subset_template and get_subset_name_for_multiple and artist will see {layer} in subset name before create.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't work if layer name is not used in subset name (which might not be all the time).

Copy link
Member

@iLLiCiTiT iLLiCiTiT Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would just not fill it. In that case the subset name would stay unchanged which is not an issue.

layer_name = "something"
# Both would work
subset_name = "renderMain" # renderMain{Layer}"
layer_fill = prepare_template_data({"layer": layer_name})
# This would just won't do anything
subset_name = subset_name.format(**layer_fill)
print(subset_name)

18 changes: 17 additions & 1 deletion openpype/hosts/photoshop/plugins/create/create_legacy_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
from openpype.pipeline import create
from openpype.hosts.photoshop import api as photoshop

from openpype.hosts.photoshop.api.plugin import (
get_subset_template,
get_subset_name_for_multiple
)


class CreateImage(create.LegacyCreator):
"""Image folder for publish."""
Expand Down Expand Up @@ -82,7 +87,12 @@ def process(self):

subset_name = creator_subset_name
if len(groups) > 1:
subset_name += group.name.title().replace(" ", "")
subset_template = get_subset_template(self.family)
subset_name = get_subset_name_for_multiple(subset_name,
subset_template,
group,
self.family,
self.data["variant"])

if group.long_name:
for directory in group.long_name[::-1]:
Expand All @@ -98,3 +108,9 @@ def process(self):
# reusing existing group, need to rename afterwards
if not create_group:
stub.rename_layer(group.id, stub.PUBLISH_ICON + group.name)

@classmethod
def get_dynamic_data(
cls, variant, task_name, asset_id, project_name, host_name
):
return {"layer": ""}