Page 1 of 1

Image "Save As" Path

Unread postPosted: Tue Aug 13, 2019 10:31 am
by briansilva
Hello! This wouldn't be too hard to hack my way through, but is there an easy way to get a full file path for an Image's output?

I know I could take the format attribute, map the dropdown indices to extensions, parse the save_as attribute for ### tokens to generate the frame number, etc. But this is prone to issues (like which form of each extension does Clarisse use, for example).

Is there a quick/robust way to get this path in Python?

Re: Image "Save As" Path

Unread postPosted: Mon Aug 26, 2019 10:55 am
by dboude
Hi,

Do you mean something like that ? https://forum.isotropix.com/viewtopic.php?f=21&t=5793

Cheers ;)

Re: Image "Save As" Path

Unread postPosted: Wed Sep 18, 2019 12:31 pm
by briansilva
Hey Démian,

Almost, but not quite -- that gives me all the paths, but for the output parameters, I still only get what the save_as parameter is literally set to.

So for example, this comes out of that script, from an Image:
/path/to/images/render_pass_v001.####

But I'd like to get a full path to the actual full image path that will be rendered, like:
/path/to/images/render_pass_v001.0034.exr

Which isn't too hard to figure out, but it requires me to do some parsing and make some assumptions about the extensions that Clarisse adds. I was hoping there was a way to use Clarisse's parsing (it must do it under the hood when the render runs) so I could trust that I'll always have the same path.

Re: Image "Save As" Path

Unread postPosted: Thu Sep 19, 2019 10:20 am
by anemoff
Hi,

There is a helper method to resolve the real filename, that we use internally, but sadly it isn't exposed in the Clarisse Python API.
So you need to write your own. Here is an example:

python code

import os
import re

def get_real_path(raw_file_path, file_ext, frame):
"""
Evaluate the real file path from a raw file path containing a frame padding expression "####".
Note: this will replace only the 1st pattern occurence.
Example: "render_####.exr" at frame 42 will output "render_0042.exr"
"""
# remove the extension if already set
file, _ = os.path.splitext(raw_file_path)

# search and replace the # pattern
match = re.search('(#+)', file)
if not match:
# by default, Clarisse pads on 5 digits when no pattern is set
result = file + '{:05d}'.format(frame) + file_ext
return result
else:
pattern_start = match.start(0)
pattern_length = match.end(0) - pattern_start
frame_str = '{:0{}d}'.format(frame, pattern_length)
result = file[:pattern_start] + frame_str + file[pattern_start + pattern_length:] + file_ext
return result

# Tests
print get_real_path('render', '.exr', 42)
print get_real_path('render.exr', '.exr', 42)
print get_real_path('render_##', '.exr', 42)
print get_real_path('render_##.exr', '.exr', 42)
print get_real_path('render_####', '.exr', 42)
print get_real_path('render_####_##', '.exr', 42)
print get_real_path('render_#####_extra', '.exr', 42)


Output:
Code: Select all
render00042.exr
render00042.exr
render_42.exr
render_42.exr
render_0042.exr
render_0042_##.exr
render_00042_extra.exr


Cheers,