This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#636 - PS created loader to load reference frame from 'render' sequence
Loader cannot do containerization for now as updates would be too difficult. (Customer doesn't mind.)
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
openpype/hosts/photoshop/plugins/load/load_image_from_sequence.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import os | ||
from avalon import photoshop | ||
from avalon.vendor import qargparse | ||
|
||
from openpype.hosts.photoshop.plugins.load.load_image import ImageLoader | ||
|
||
stub = photoshop.stub() | ||
|
||
|
||
class ImageFromSequenceLoader(ImageLoader): | ||
""" Load specifing image from sequence | ||
Used only as quick load of reference file from a sequence. | ||
Plain ImageLoader picks first frame from sequence. | ||
Loads only existing files - currently not possible to limit loaders | ||
to single select - multiselect. If user selects multiple repres, list | ||
for all of them is provided, but selection is only single file. | ||
This loader will be triggered multiple times, but selected name will | ||
match only to proper path. | ||
Loader doesnt do containerization as there is currently no data model | ||
of 'frame of rendered files' (only rendered sequence), update would be | ||
difficult. | ||
""" | ||
|
||
families = ["render"] | ||
representations = ["*"] | ||
options = [] | ||
|
||
def load(self, context, name=None, namespace=None, data=None): | ||
if data.get("frame"): | ||
self.fname = os.path.join(os.path.dirname(self.fname), | ||
data["frame"]) | ||
if not os.path.exists(self.fname): | ||
return | ||
|
||
layer_name = self._get_unique_layer_name(context["asset"]["name"], | ||
name) | ||
with photoshop.maintained_selection(): | ||
layer = stub.import_smart_object(self.fname, layer_name) | ||
|
||
self[:] = [layer] | ||
namespace = namespace or layer_name | ||
|
||
return namespace | ||
|
||
@classmethod | ||
def get_options(cls, repre_contexts): | ||
""" | ||
Returns list of files for selected 'repre_contexts'. | ||
It returns only files with same extension as in context as it is | ||
expected that context points to sequence of frames. | ||
Returns: | ||
(list) of qargparse.Choice | ||
""" | ||
files = [] | ||
for context in repre_contexts: | ||
fname = ImageLoader.filepath_from_context(context) | ||
_, file_extension = os.path.splitext(fname) | ||
|
||
for file_name in os.listdir(os.path.dirname(fname)): | ||
if not file_name.endswith(file_extension): | ||
continue | ||
files.append(file_name) | ||
|
||
# return selection only if there is something | ||
if not files or len(files) <= 1: | ||
return [] | ||
|
||
return [ | ||
qargparse.Choice( | ||
"frame", | ||
label="Select specific file", | ||
items=files, | ||
default=0, | ||
help="Which frame should be loaded?" | ||
) | ||
] | ||
|
||
def update(self, container, representation): | ||
"""No update possible, not containerized.""" | ||
pass | ||
|
||
def remove(self, container): | ||
"""No update possible, not containerized.""" | ||
pass |