Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#327: Creer un validator de blendMode sur les layers dans photoshop #43

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<error id="main">
<title>BlendMode Error</title>
<description>
## Invalid blendMode on layer or group

Layer must be in Normal blend and Groups in PassThrought.

### How to repair?

You can fix this with "repair" button on the right and press Refresh publishing button at the bottom right.
</description>
</error>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import pyblish.api
from openpype.pipeline.publish import (
ValidateContentsOrder,
PublishXmlValidationError,
OptionalPyblishPluginMixin
)
from openpype.hosts.photoshop import api as photoshop


class ValidateBlendModeRepair(pyblish.api.Action):
"""Repair the instance asset."""

label = "Repair"
icon = "wrench"
on = "failed"

def process(self, context, plugin):

stub = photoshop.stub()
failed = context.data['transientData'][ValidateBlendMode.__name__]

for layer, info in failed.items():
stub.set_blendmode(layer_name=layer, blendMode_name=info["defaultBlendMode"])


class ValidateBlendMode(
OptionalPyblishPluginMixin,
pyblish.api.ContextPlugin
):
"""Validate if the blendMode is set properly on Layers, NORMAL, and Groups, PASSTHROUGH
"""

label = "Validate BlendMode"
hosts = ["photoshop"]
order = ValidateContentsOrder
families = ["image"]
actions = [ValidateBlendModeRepair]
optional = True
active = False

def process(self, context):

if not self.is_active(context.data):
return

PASSTHROUGH = "passThrough"
Copy link
Contributor

Choose a reason for hiding this comment

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

Selon moi ici il faut retirer PASSTHROUGH et NORMAL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

En considérant qu'on garde le transfert d'info par str, on peut conserver ces var ou pas du coup ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes

NORMAL = "normal"
returnDict = {}
msg = ""

stub = photoshop.stub()
layers = stub.get_layers()

for layer in layers:
layerDict = {}
if (layer.group and layer.blendMode != PASSTHROUGH) or (not layer.group and layer.blendMode != NORMAL):
Copy link
Contributor

Choose a reason for hiding this comment

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

Et ici faire if (layer.group and layer.blendMode != BlendMode.PassThrough) or (not layer.group and layer.blendMode != BlendMode.NormalBlend):

(Voir https://github.com/loonghao/photoshop-python-api/blob/main/photoshop/api/enumerations.py#L91 )

Copy link
Contributor

Choose a reason for hiding this comment

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

il y a une logique typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID('mode'))); pour obtenir une string, voir si il y a la même pour avoir un id (int)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comme vu dans la pr sur OpenPype, il n'y a pas de lien entre les classes et fonction dans le jsx et celles du py, les ID des blendModes ne correspondent pas entre l'api jsx et l'api python de Photoshop.
En passant par un eval('BlendMode.' + blendModeName.toUpperCase()), on va conserver la transmission d'info par str je pense

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes

layerDict["actualBlendMode"] = layer.blendMode
layerDict["defaultBlendMode"] = PASSTHROUGH if layer.group else NORMAL
Copy link
Contributor

Choose a reason for hiding this comment

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

Passer ici un id une non une string

returnDict[layer.name] = layerDict

typeStr = "Group" if layer.group else "Layer"
msg = "{}\n\n The {} {} is set to {}.".format(msg, typeStr, layer.name, layer.blendMode)

else:
Copy link
Contributor

Choose a reason for hiding this comment

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

le else dans cette boucle semble inutile

continue

if returnDict:
if not context.data.get('transientData'):
context.data['transientData'] = dict()

context.data['transientData'][self.__class__.__name__] = returnDict

raise PublishXmlValidationError(self, msg)