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 #3407 from pypeclub/bugfix/OP-3351_Nuke-still-imag…
Browse files Browse the repository at this point in the history
…e-representation-fix

Nuke: Collect representation files based on Write
  • Loading branch information
iLLiCiTiT authored Jun 24, 2022
2 parents 441b58c + 4c6677e commit 1a1d9ec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
27 changes: 18 additions & 9 deletions openpype/hosts/nuke/plugins/publish/extract_render_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,22 @@ def process(self, instance):
self.log.info("Start frame: {}".format(first_frame))
self.log.info("End frame: {}".format(last_frame))

# write node url might contain nuke's ctl expressin
# as [python ...]/path...
path = node["file"].evaluate()
node_file = node["file"]
# Collecte expected filepaths for each frame
# - for cases that output is still image is first created set of
# paths which is then sorted and converted to list
expected_paths = list(sorted({
node_file.evaluate(frame)
for frame in range(first_frame, last_frame + 1)
}))
# Extract only filenames for representation
filenames = [
os.path.basename(filepath)
for filepath in expected_paths
]

# Ensure output directory exists.
out_dir = os.path.dirname(path)
out_dir = os.path.dirname(expected_paths[0])
if not os.path.exists(out_dir):
os.makedirs(out_dir)

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

collected_frames = os.listdir(out_dir)
if len(collected_frames) == 1:
if len(filenames) == 1:
repre = {
'name': ext,
'ext': ext,
'files': collected_frames.pop(),
'files': filenames[0],
"stagingDir": out_dir
}
else:
Expand All @@ -81,7 +90,7 @@ def process(self, instance):
'ext': ext,
'frameStart': "%0{}d".format(
len(str(last_frame))) % first_frame,
'files': collected_frames,
'files': filenames,
"stagingDir": out_dir
}
instance.data["representations"].append(repre)
Expand All @@ -105,7 +114,7 @@ def process(self, instance):
families.remove('still.local')
instance.data["families"] = families

collections, remainder = clique.assemble(collected_frames)
collections, remainder = clique.assemble(filenames)
self.log.info('collections: {}'.format(str(collections)))

if collections:
Expand Down
21 changes: 18 additions & 3 deletions openpype/hosts/nuke/plugins/publish/precollect_writes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,21 @@ def process(self, instance):
first_frame = int(node["first"].getValue())
last_frame = int(node["last"].getValue())

# get path
# Prepare expected output paths by evaluating each frame of write node
# - paths are first collected to set to avoid duplicated paths, then
# sorted and converted to list
node_file = node["file"]
expected_paths = list(sorted({
node_file.evaluate(frame)
for frame in range(first_frame, last_frame + 1)
}))
expected_filenames = [
os.path.basename(filepath)
for filepath in expected_paths
]
path = nuke.filename(node)
output_dir = os.path.dirname(path)

self.log.debug('output dir: {}'.format(output_dir))

# create label
Expand All @@ -83,8 +95,11 @@ def process(self, instance):
}

try:
collected_frames = [f for f in os.listdir(output_dir)
if ext in f]
collected_frames = [
filename
for filename in os.listdir(output_dir)
if filename in expected_filenames
]
if collected_frames:
collected_frames_len = len(collected_frames)
frame_start_str = "%0{}d".format(
Expand Down

0 comments on commit 1a1d9ec

Please sign in to comment.