mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
#636 - un subclassed loader from sequence, created lib for reusable methods
Loader from sequence didnt was dropping connection to PS after first successful import
This commit is contained in:
parent
68e9102f72
commit
852a2f35aa
3 changed files with 43 additions and 31 deletions
26
openpype/hosts/photoshop/plugins/lib.py
Normal file
26
openpype/hosts/photoshop/plugins/lib.py
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def get_unique_layer_name(layers, asset_name, subset_name):
|
||||||
|
"""
|
||||||
|
Gets all layer names and if 'asset_name_subset_name' is present, it
|
||||||
|
increases suffix by 1 (eg. creates unique layer name - for Loader)
|
||||||
|
Args:
|
||||||
|
layers (list) of dict with layers info (name, id etc.)
|
||||||
|
asset_name (string):
|
||||||
|
subset_name (string):
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
(string): name_00X (without version)
|
||||||
|
"""
|
||||||
|
name = "{}_{}".format(asset_name, subset_name)
|
||||||
|
names = {}
|
||||||
|
for layer in layers:
|
||||||
|
layer_name = re.sub(r'_\d{3}$', '', layer.name)
|
||||||
|
if layer_name in names.keys():
|
||||||
|
names[layer_name] = names[layer_name] + 1
|
||||||
|
else:
|
||||||
|
names[layer_name] = 1
|
||||||
|
occurrences = names.get(name, 0)
|
||||||
|
|
||||||
|
return "{}_{:0>3d}".format(name, occurrences + 1)
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
from avalon import api, photoshop
|
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from avalon import api, photoshop
|
||||||
|
|
||||||
|
from openpype.hosts.photoshop.plugins.lib import get_unique_layer_name
|
||||||
|
|
||||||
stub = photoshop.stub()
|
stub = photoshop.stub()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -15,8 +17,9 @@ class ImageLoader(api.Loader):
|
||||||
representations = ["*"]
|
representations = ["*"]
|
||||||
|
|
||||||
def load(self, context, name=None, namespace=None, data=None):
|
def load(self, context, name=None, namespace=None, data=None):
|
||||||
layer_name = self._get_unique_layer_name(context["asset"]["name"],
|
layer_name = get_unique_layer_name(stub.get_layers(),
|
||||||
name)
|
context["asset"]["name"],
|
||||||
|
name)
|
||||||
with photoshop.maintained_selection():
|
with photoshop.maintained_selection():
|
||||||
layer = stub.import_smart_object(self.fname, layer_name)
|
layer = stub.import_smart_object(self.fname, layer_name)
|
||||||
|
|
||||||
|
|
@ -69,25 +72,3 @@ class ImageLoader(api.Loader):
|
||||||
|
|
||||||
def switch(self, container, representation):
|
def switch(self, container, representation):
|
||||||
self.update(container, representation)
|
self.update(container, representation)
|
||||||
|
|
||||||
def _get_unique_layer_name(self, asset_name, subset_name):
|
|
||||||
"""
|
|
||||||
Gets all layer names and if 'name' is present in them, increases
|
|
||||||
suffix by 1 (eg. creates unique layer name - for Loader)
|
|
||||||
Args:
|
|
||||||
name (string): in format asset_subset
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
(string): name_00X (without version)
|
|
||||||
"""
|
|
||||||
name = "{}_{}".format(asset_name, subset_name)
|
|
||||||
names = {}
|
|
||||||
for layer in stub.get_layers():
|
|
||||||
layer_name = re.sub(r'_\d{3}$', '', layer.name)
|
|
||||||
if layer_name in names.keys():
|
|
||||||
names[layer_name] = names[layer_name] + 1
|
|
||||||
else:
|
|
||||||
names[layer_name] = 1
|
|
||||||
occurrences = names.get(name, 0)
|
|
||||||
|
|
||||||
return "{}_{:0>3d}".format(name, occurrences + 1)
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from avalon import api
|
||||||
from avalon import photoshop
|
from avalon import photoshop
|
||||||
from avalon.vendor import qargparse
|
from avalon.vendor import qargparse
|
||||||
|
|
||||||
from openpype.hosts.photoshop.plugins.load.load_image import ImageLoader
|
from openpype.hosts.photoshop.plugins.lib import get_unique_layer_name
|
||||||
|
|
||||||
stub = photoshop.stub()
|
stub = photoshop.stub()
|
||||||
|
|
||||||
|
|
||||||
class ImageFromSequenceLoader(ImageLoader):
|
class ImageFromSequenceLoader(api.Loader):
|
||||||
""" Load specifing image from sequence
|
""" Load specifing image from sequence
|
||||||
|
|
||||||
Used only as quick load of reference file from a sequence.
|
Used only as quick load of reference file from a sequence.
|
||||||
|
|
@ -36,8 +38,11 @@ class ImageFromSequenceLoader(ImageLoader):
|
||||||
if not os.path.exists(self.fname):
|
if not os.path.exists(self.fname):
|
||||||
return
|
return
|
||||||
|
|
||||||
layer_name = self._get_unique_layer_name(context["asset"]["name"],
|
stub = photoshop.stub()
|
||||||
name)
|
layer_name = get_unique_layer_name(stub.get_layers(),
|
||||||
|
context["asset"]["name"],
|
||||||
|
name)
|
||||||
|
|
||||||
with photoshop.maintained_selection():
|
with photoshop.maintained_selection():
|
||||||
layer = stub.import_smart_object(self.fname, layer_name)
|
layer = stub.import_smart_object(self.fname, layer_name)
|
||||||
|
|
||||||
|
|
@ -59,7 +64,7 @@ class ImageFromSequenceLoader(ImageLoader):
|
||||||
"""
|
"""
|
||||||
files = []
|
files = []
|
||||||
for context in repre_contexts:
|
for context in repre_contexts:
|
||||||
fname = ImageLoader.filepath_from_context(context)
|
fname = ImageFromSequenceLoader.filepath_from_context(context)
|
||||||
_, file_extension = os.path.splitext(fname)
|
_, file_extension = os.path.splitext(fname)
|
||||||
|
|
||||||
for file_name in os.listdir(os.path.dirname(fname)):
|
for file_name in os.listdir(os.path.dirname(fname)):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue