_SaveRenderWindowAs command saving to different path than specified

Here’s my script:

def batch_render_named_views_alt(path):

    if not os.path.exists(path):
        os.makedirs(path)

    named_views = rs.NamedViews()
    for view in named_views:
        rs.RestoreNamedView(view)
        filename = f"{path}{view}.png"
        print(f"Saving to file {filename}")
        rs.Command(f"_Render", True)
        rs.Command(f"-_SaveRenderWindowAs {filename} _Enter", True)
        rs.Command("_CloseRenderWindow _Enter")

And here’s the CommandHistory:

Command: _Render
Processing light table
Processing geometry table
Rendering time: 0d 0h 0m 5s
Command: -_SaveRenderWindowAs
Save file name ( Browse )/Users/dpd/Repos/otherwise-media/products/paris/renders/round/ruby/rose-gold/1.5/upright-0-0.png
Image successfully saved as /Users/dpd/Repos/otherwise-media/products/paris/renders/round/diamond/yellow-gold/1.5/upright-0-0.png

As you can see the 'Save file name: /Users/dpd/Repos/otherwise-media/products/paris/renders/round/ruby/rose-gold/1.5/upright-0-0.png and file name it actually saves to are different: /Users/dpd/Repos/otherwise-media/products/paris/renders/round/diamond/yellow-gold/1.5/upright-0-0.png

This seems to happen when invoking _SaveRenderWindowAs multiple times with different paths (which correspond to different renders / materials applied to objects.

It’s almost as if there’s some weird caching going on, or falling back to some ‘default’ save path.

Any ideas would be appreciated!

Hi David - how many of these do you run in sequence before it goes weird?
Ah, it’s on Mac I guess… I’ll try there.

-Pascal

Hi Pascal,

Thanks for the reply - this is a sample of the script:

def render(stone, shank):
    for stone_material in stone:
        apply_material_to_object("stone", stone_material)
        for shank_material in shank:
            apply_material_to_object("shank", shank_material)
            save_path = build_save_path(stone_material, shank_material)
            print(f"Batch render started for {stone_material} > {shank_material}. Renders will be saved to: {save_path}")
            batch_render_named_views(save_path)

stone_materials = ["diamond", "emerald", "ruby"]
shank_materials = ["yellow-gold","white-gold", "rose-gold"]
render(stone_materials, shank_materials)

When running the script for the first time the diamond and emerald stones render ok, but the ruby stone seems to always save to the diamond/yellow-gold path (the first combination)

Then any subsequent attempt to _SaveRenderWindowAs with to given path always save to the diamond/yellow-gold until the application is restarted.

I hope that helps but let me know if you need anything else

A quick update on this - it appeared to be a particular Named View that was always being saved to the wrong path. I tried just renaming the Named View and that seems to have fixed the problem!