Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1515 from pypeclub/bugfix/maya_playblast_collecti…
Browse files Browse the repository at this point in the history
…ng_wrong_frames_3
  • Loading branch information
mkolar authored May 17, 2021
2 parents 1165d3b + 153dc4b commit 81910d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 49 deletions.
63 changes: 15 additions & 48 deletions openpype/hosts/maya/plugins/publish/extract_playblast.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,25 @@ def process(self, instance):
# Remove panel key since it's internal value to capture_gui
preset.pop("panel", None)


self.log.info('using viewport preset: {}'.format(preset))

path = capture.capture(**preset)
playblast = self._fix_playblast_output_path(path)

self.log.info("file list {}".format(playblast))
self.log.debug("playblast path {}".format(path))

collected_frames = os.listdir(stagingdir)
collections, remainder = clique.assemble(collected_frames)
input_path = os.path.join(
stagingdir, collections[0].format('{head}{padding}{tail}'))
self.log.info("input {}".format(input_path))
collected_files = os.listdir(stagingdir)
collections, remainder = clique.assemble(collected_files)

self.log.debug("filename {}".format(filename))
frame_collection = None
for collection in collections:
filebase = collection.format('{head}').rstrip(".")
self.log.debug("collection head {}".format(filebase))
if filebase in filename:
frame_collection = collection
self.log.info(
"we found collection of interest {}".format(
str(frame_collection)))

if "representations" not in instance.data:
instance.data["representations"] = []
Expand All @@ -119,12 +125,11 @@ def process(self, instance):

# Add camera node name to representation data
camera_node_name = pm.ls(camera)[0].getTransform().name()


representation = {
'name': 'png',
'ext': 'png',
'files': collected_frames,
'files': list(frame_collection),
"stagingDir": stagingdir,
"frameStart": start,
"frameEnd": end,
Expand All @@ -135,44 +140,6 @@ def process(self, instance):
}
instance.data["representations"].append(representation)

def _fix_playblast_output_path(self, filepath):
"""Workaround a bug in maya.cmds.playblast to return correct filepath.
When the `viewer` argument is set to False and maya.cmds.playblast
does not automatically open the playblasted file the returned
filepath does not have the file's extension added correctly.
To workaround this we just glob.glob() for any file extensions and
assume the latest modified file is the correct file and return it.
"""
# Catch cancelled playblast
if filepath is None:
self.log.warning("Playblast did not result in output path. "
"Playblast is probably interrupted.")
return None

# Fix: playblast not returning correct filename (with extension)
# Lets assume the most recently modified file is the correct one.
if not os.path.exists(filepath):
directory = os.path.dirname(filepath)
filename = os.path.basename(filepath)
# check if the filepath is has frame based filename
# example : capture.####.png
parts = filename.split(".")
if len(parts) == 3:
query = os.path.join(directory, "{}.*.{}".format(parts[0],
parts[-1]))
files = glob.glob(query)
else:
files = glob.glob("{}.*".format(filepath))

if not files:
raise RuntimeError("Couldn't find playblast from: "
"{0}".format(filepath))
filepath = max(files, key=os.path.getmtime)

return filepath


@contextlib.contextmanager
def maintained_time():
Expand Down
2 changes: 1 addition & 1 deletion openpype/plugins/publish/extract_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ExtractReview(pyblish.api.InstancePlugin):
profiles = None

def process(self, instance):
self.log.debug(instance.data["representations"])
self.log.debug(str(instance.data["representations"]))
# Skip review when requested.
if not instance.data.get("review", True):
return
Expand Down

0 comments on commit 81910d3

Please sign in to comment.