OP-2766 - merge feature/OP-2895_Photoshop-create-image-without-instance

Added functionality to create flatten image if no image instances present.
This commit is contained in:
Petr Kalis 2022-04-01 16:12:19 +02:00
commit 5ebca946fe
6 changed files with 76 additions and 9 deletions

View file

@ -1,7 +1,10 @@
import pprint
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):
@ -10,6 +13,10 @@ class CollectInstances(pyblish.api.ContextPlugin):
Collects publishable instances from file metadata or enhance
already collected by creator (family == "image").
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"
"""
@ -20,6 +27,8 @@ class CollectInstances(pyblish.api.ContextPlugin):
families_mapping = {
"image": []
}
# configurable in Settings
flatten_subset_template = ""
def process(self, context):
instance_by_layer_id = {}
@ -34,8 +43,11 @@ class CollectInstances(pyblish.api.ContextPlugin):
layer_items = stub.get_layers()
layers_meta = stub.get_layers_metadata()
instance_names = []
all_layer_ids = []
for layer_item in layer_items:
layer_meta_data = stub.read(layer_item, layers_meta)
all_layer_ids.append(layer_item.id)
# Skip layers without metadata.
if layer_meta_data is None:
@ -70,3 +82,33 @@ class CollectInstances(pyblish.api.ContextPlugin):
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))

View file

@ -27,14 +27,10 @@ class ExtractImage(openpype.api.Extractor):
with photoshop.maintained_selection():
self.log.info("Extracting %s" % str(list(instance)))
with photoshop.maintained_visibility():
self.log.info("instance.data:: {}".format(instance.data))
print("instance.data::: {}".format(instance.data))
ids = set()
layer = instance.data.get("layer")
self.log.info("layer:: {}".format(layer))
print("layer::: {}".format(layer))
if not layer:
return
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))

View file

@ -155,6 +155,9 @@ class ExtractReview(openpype.api.Extractor):
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)

View file

@ -12,6 +12,9 @@
"flatten_subset_template": "",
"color_code_mapping": []
},
"CollectInstances": {
"flatten_subset_template": ""
},
"ValidateContainers": {
"enabled": true,
"optional": true,
@ -44,4 +47,4 @@
"create_first_version": false,
"custom_templates": []
}
}
}

View file

@ -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",
@ -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",

View file

@ -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.