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

Photoshop: create image without instance #3001

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions openpype/hosts/photoshop/plugins/publish/collect_instances.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from avalon import api
import pyblish.api

from openpype.settings import get_project_settings
from openpype.hosts.photoshop import api as photoshop
from openpype.lib import prepare_template_data


class CollectInstances(pyblish.api.ContextPlugin):
Expand All @@ -9,6 +12,10 @@ class CollectInstances(pyblish.api.ContextPlugin):
This collector takes into account assets that are associated with
an LayerSet and marked with a unique identifier;

If no image instances are explicitly created, it looks if there is value
in `flatten_subset_template` (configurable in Settings), in that case it
produces flatten image with all visible layers.

Identifier:
id (str): "pyblish.avalon.instance"
"""
Expand All @@ -19,13 +26,17 @@ class CollectInstances(pyblish.api.ContextPlugin):
families_mapping = {
"image": []
}
# configurable in Settings
flatten_subset_template = ""

def process(self, context):
stub = photoshop.stub()
layers = stub.get_layers()
layers_meta = stub.get_layers_metadata()
instance_names = []
all_layer_ids = []
for layer in layers:
all_layer_ids.append(layer.id)
layer_data = stub.read(layer, layers_meta)

# Skip layers without metadata.
Expand Down Expand Up @@ -59,3 +70,33 @@ def process(self, context):
if len(instance_names) != len(set(instance_names)):
self.log.warning("Duplicate instances found. " +
"Remove unwanted via SubsetManager")

if len(instance_names) == 0 and self.flatten_subset_template:
project_name = context.data["projectEntity"]["name"]
variants = get_project_settings(project_name).get(
"photoshop", {}).get(
"create", {}).get(
"CreateImage", {}).get(
"defaults", [''])
family = "image"
task_name = api.Session["AVALON_TASK"]
asset_name = context.data["assetEntity"]["name"]

fill_pairs = {
"variant": variants[0],
"family": family,
"task": task_name
}

subset = self.flatten_subset_template.format(
**prepare_template_data(fill_pairs))

instance = context.create_instance(subset)
instance.data["family"] = family
instance.data["asset"] = asset_name
instance.data["subset"] = subset
instance.data["ids"] = all_layer_ids
instance.data["families"] = self.families_mapping[family]
instance.data["publish"] = True

self.log.info("flatten instance: {} ".format(instance.data))
4 changes: 3 additions & 1 deletion openpype/hosts/photoshop/plugins/publish/extract_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def process(self, instance):
with photoshop.maintained_selection():
self.log.info("Extracting %s" % str(list(instance)))
with photoshop.maintained_visibility():
ids = set()
layer = instance.data.get("layer")
ids = set([layer.id])
if layer:
ids.add(layer.id)
add_ids = instance.data.pop("ids", None)
if add_ids:
ids.update(set(add_ids))
Expand Down
3 changes: 3 additions & 0 deletions openpype/hosts/photoshop/plugins/publish/extract_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ def _get_layers_from_image_instances(self, instance):
for image_instance in instance.context:
if image_instance.data["family"] != "image":
continue
if not image_instance.data.get("layer"):
# dummy instance for flatten image
continue
layers.append(image_instance.data.get("layer"))

return sorted(layers)
Expand Down
5 changes: 4 additions & 1 deletion openpype/settings/defaults/project_settings/photoshop.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"flatten_subset_template": "",
"color_code_mapping": []
},
"CollectInstances": {
"flatten_subset_template": ""
},
"ValidateContainers": {
"enabled": true,
"optional": true,
Expand Down Expand Up @@ -44,4 +47,4 @@
"create_first_version": false,
"custom_templates": []
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"children": [
{
"type": "label",
"label": "Set color for publishable layers, set its resulting family and template for subset name. Can create flatten image from published instances"
"label": "Set color for publishable layers, set its resulting family and template for subset name. \nCan create flatten image from published instances.(Applicable only for remote publishing!)"
},
{
"type": "boolean",
Expand Down Expand Up @@ -108,6 +108,23 @@
}
]
},
{
"type": "dict",
"collapsible": true,
"key": "CollectInstances",
"label": "Collect Instances",
"children": [
{
"type": "label",
"label": "Name for flatten image created if no image instance present"
},
{
"type": "text",
"key": "flatten_subset_template",
"label": "Subset template for flatten image"
}
]
},
{
"type": "schema_template",
"name": "template_publish_plugin",
Expand Down
6 changes: 6 additions & 0 deletions website/docs/artist_hosts_photoshop.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ With the `Creator` you have a variety of options to create:
- Uncheck `Use selection`.
- This will create a single group named after the `Subset` in the `Creator`.

#### Simplified publish

There is a simplified workflow for simple use case where only single image should be created containing all visible layers.
No image instances must be present in a workfile and `project_settings/photoshop/publish/CollectInstances/flatten_subset_template` must be filled in Settings.
Then artists just need to hit 'Publish' button in menu.

### Publish

When you are ready to share some work, you will need to publish. This is done by opening the `Pyblish` through the extensions `Publish` button.
Expand Down