mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
Fixed fullName, implemented imprint
This commit is contained in:
parent
41c1016952
commit
a9f146e2fc
7 changed files with 96 additions and 20 deletions
|
|
@ -13,15 +13,34 @@ class PhotoshopClientStub():
|
|||
self.client = self.websocketserver.get_client()
|
||||
|
||||
def read(self, layer):
|
||||
layers_data = {}
|
||||
res = self.websocketserver.call(self.client.call('Photoshop.read'))
|
||||
try:
|
||||
layers_data = json.loads(res)
|
||||
except json.decoder.JSONDecodeError:
|
||||
pass
|
||||
layers_data = self._get_layers_metadata()
|
||||
|
||||
return layers_data.get(str(layer.id))
|
||||
|
||||
def imprint(self, layer, data):
|
||||
layers_data = self._get_layers_metadata()
|
||||
# json.dumps writes integer values in a dictionary to string, so
|
||||
# anticipating it here.
|
||||
if str(layer.id) in layers_data:
|
||||
layers_data[str(layer.id)].update(data)
|
||||
else:
|
||||
layers_data[str(layer.id)] = data
|
||||
|
||||
# Ensure only valid ids are stored.
|
||||
layer_ids = [layer.id for layer in self.get_layers()]
|
||||
cleaned_data = {}
|
||||
|
||||
for id in layers_data:
|
||||
if int(id) in layer_ids:
|
||||
cleaned_data[id] = layers_data[id]
|
||||
|
||||
payload = json.dumps(cleaned_data, indent=4)
|
||||
|
||||
res = self.websocketserver.call(self.client.call
|
||||
('Photoshop.imprint',
|
||||
payload=payload)
|
||||
)
|
||||
|
||||
def get_layers(self):
|
||||
"""
|
||||
Returns JSON document with all(?) layers in active document.
|
||||
|
|
@ -77,18 +96,34 @@ class PhotoshopClientStub():
|
|||
layers=layer_ids)
|
||||
)
|
||||
|
||||
def get_active_document_full_name(self):
|
||||
"""
|
||||
Returns full name with path of active document via ws call
|
||||
:return: <string> full path with name
|
||||
"""
|
||||
res = self.websocketserver.call(
|
||||
self.client.call('Photoshop.get_active_document_full_name'))
|
||||
|
||||
return res
|
||||
|
||||
def get_active_document_name(self):
|
||||
"""
|
||||
Returns just a name of active document via ws call
|
||||
:return: <string> file name
|
||||
"""
|
||||
res = self.websocketserver.call(self.client.call
|
||||
('Photoshop.get_active_document_name'))
|
||||
|
||||
return res
|
||||
|
||||
def set_visible(self, layer_id, visibility):
|
||||
print("set_visible {}, {}".format(layer_id, visibility))
|
||||
def save(self):
|
||||
"""
|
||||
Saves active document
|
||||
:return: None
|
||||
"""
|
||||
res = self.websocketserver.call(self.client.call
|
||||
('Photoshop.set_visible',
|
||||
layer_id=layer_id,
|
||||
visibility=visibility))
|
||||
('Photoshop.save'))
|
||||
|
||||
|
||||
def saveAs(self, image_path, ext, as_copy):
|
||||
res = self.websocketserver.call(self.client.call
|
||||
|
|
@ -97,6 +132,22 @@ class PhotoshopClientStub():
|
|||
ext=ext,
|
||||
as_copy=as_copy))
|
||||
|
||||
def set_visible(self, layer_id, visibility):
|
||||
print("set_visible {}, {}".format(layer_id, visibility))
|
||||
res = self.websocketserver.call(self.client.call
|
||||
('Photoshop.set_visible',
|
||||
layer_id=layer_id,
|
||||
visibility=visibility))
|
||||
|
||||
def _get_layers_metadata(self):
|
||||
layers_data = {}
|
||||
res = self.websocketserver.call(self.client.call('Photoshop.read'))
|
||||
try:
|
||||
layers_data = json.loads(res)
|
||||
except json.decoder.JSONDecodeError:
|
||||
pass
|
||||
return layers_data
|
||||
|
||||
def close(self):
|
||||
self.client.close()
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ import os
|
|||
import pyblish.api
|
||||
from avalon import photoshop
|
||||
|
||||
from pype.modules.websocket_server.clients.photoshop_client import \
|
||||
PhotoshopClientStub
|
||||
|
||||
|
||||
class CollectCurrentFile(pyblish.api.ContextPlugin):
|
||||
"""Inject the current working file into context"""
|
||||
|
|
@ -12,6 +15,7 @@ class CollectCurrentFile(pyblish.api.ContextPlugin):
|
|||
hosts = ["photoshop"]
|
||||
|
||||
def process(self, context):
|
||||
photoshop_client = PhotoshopClientStub()
|
||||
context.data["currentFile"] = os.path.normpath(
|
||||
photoshop.app().ActiveDocument.FullName
|
||||
photoshop_client.get_active_document_full_name()
|
||||
).replace("\\", "/")
|
||||
|
|
|
|||
|
|
@ -33,8 +33,14 @@ class CollectInstances(pyblish.api.ContextPlugin):
|
|||
# for timing
|
||||
photoshop_client = PhotoshopClientStub()
|
||||
layers = photoshop_client.get_layers()
|
||||
|
||||
for layer in layers:
|
||||
layer_data = photoshop_client.read(layer)
|
||||
self.log.info("layer_data {}".format(layer_data))
|
||||
|
||||
photoshop_client.imprint(layer, layer_data)
|
||||
new_layer_data = photoshop_client.read(layer)
|
||||
assert layer_data == new_layer_data
|
||||
|
||||
# Skip layers without metadata.
|
||||
if layer_data is None:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import pype.api
|
||||
from avalon import photoshop
|
||||
|
||||
from pype.modules.websocket_server.clients.photoshop_client import \
|
||||
PhotoshopClientStub
|
||||
|
||||
from datetime import datetime
|
||||
class ExtractSaveScene(pype.api.Extractor):
|
||||
"""Save scene before extraction."""
|
||||
|
|
@ -11,7 +14,8 @@ class ExtractSaveScene(pype.api.Extractor):
|
|||
families = ["workfile"]
|
||||
|
||||
def process(self, instance):
|
||||
photoshop_client = PhotoshopClientStub()
|
||||
start = datetime.now()
|
||||
photoshop.app().ActiveDocument.Save()
|
||||
photoshop_client.save()
|
||||
self.log.info(
|
||||
"ExtractSaveScene took {}".format(datetime.now() - start))
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ from pype.action import get_errored_plugins_from_data
|
|||
from pype.lib import version_up
|
||||
from avalon import photoshop
|
||||
|
||||
from pype.modules.websocket_server.clients.photoshop_client import \
|
||||
PhotoshopClientStub
|
||||
|
||||
class IncrementWorkfile(pyblish.api.InstancePlugin):
|
||||
"""Increment the current workfile.
|
||||
|
|
@ -24,6 +26,7 @@ class IncrementWorkfile(pyblish.api.InstancePlugin):
|
|||
)
|
||||
|
||||
scene_path = version_up(instance.context.data["currentFile"])
|
||||
photoshop.app().ActiveDocument.SaveAs(scene_path)
|
||||
photoshop_client = PhotoshopClientStub()
|
||||
photoshop_client.saveAs(scene_path, 'psd', True)
|
||||
|
||||
self.log.info("Incremented workfile to: {}".format(scene_path))
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import pyblish.api
|
|||
import pype.api
|
||||
from avalon import photoshop
|
||||
|
||||
from pype.modules.websocket_server.clients.photoshop_client import \
|
||||
PhotoshopClientStub
|
||||
|
||||
class ValidateInstanceAssetRepair(pyblish.api.Action):
|
||||
"""Repair the instance asset."""
|
||||
|
|
@ -23,11 +25,14 @@ class ValidateInstanceAssetRepair(pyblish.api.Action):
|
|||
|
||||
# Apply pyblish.logic to get the instances for the plug-in
|
||||
instances = pyblish.api.instances_by_plugin(failed, plugin)
|
||||
|
||||
photoshop_client = PhotoshopClientStub()
|
||||
for instance in instances:
|
||||
data = photoshop.read(instance[0])
|
||||
self.log.info("validate_instance_asset instance[0] {}".format(instance[0]))
|
||||
self.log.info("validate_instance_asset instance {}".format(instance))
|
||||
data = photoshop_client.read(instance[0])
|
||||
|
||||
data["asset"] = os.environ["AVALON_ASSET"]
|
||||
photoshop.imprint(instance[0], data)
|
||||
photoshop_client.imprint(instance[0], data)
|
||||
|
||||
|
||||
class ValidateInstanceAsset(pyblish.api.InstancePlugin):
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import pyblish.api
|
|||
import pype.api
|
||||
from avalon import photoshop
|
||||
|
||||
from pype.modules.websocket_server.clients.photoshop_client import \
|
||||
PhotoshopClientStub
|
||||
|
||||
class ValidateNamingRepair(pyblish.api.Action):
|
||||
"""Repair the instance asset."""
|
||||
|
|
@ -21,13 +23,14 @@ class ValidateNamingRepair(pyblish.api.Action):
|
|||
|
||||
# Apply pyblish.logic to get the instances for the plug-in
|
||||
instances = pyblish.api.instances_by_plugin(failed, plugin)
|
||||
|
||||
photoshop_client = PhotoshopClientStub()
|
||||
for instance in instances:
|
||||
self.log.info("validate_naming instance {}".format(instance))
|
||||
name = instance.data["name"].replace(" ", "_")
|
||||
instance[0].Name = name
|
||||
data = photoshop.read(instance[0])
|
||||
data = photoshop_client.read(instance[0])
|
||||
data["subset"] = "image" + name
|
||||
photoshop.imprint(instance[0], data)
|
||||
photoshop_client.imprint(instance[0], data)
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue