Forum: Poser 13


Subject: Poser 13: Python script to batch render MP4s?

tnpir4002 opened this issue on Sep 30, 2024 ยท 10 posts


HartyBart posted Sun, 27 October 2024 at 12:21 PM

Looks good, thanks for posting, and glad it's working. For ease of reading, here's the formatted script...


# Batch render sets of PNG animation sequences, from many Poser .PZ3 scene files

import os
import poser
import time

# Directory containing the .PZ3 files
selected_directory = r"C:\Path\To\Your\Files"

# Find and process all .PZ3 files in the directory
pz3_files = [f for f in os.listdir(selected_directory) if f.lower().endswith('.pz3')]

if not pz3_files:
    print("No PZ3 files found in the directory.")

else:
    for pz3_file in pz3_files:
        pz3_path = os.path.join(selected_directory, pz3_file)
        try:
            # Open the .PZ3 file
            print(f"Attempting to open {pz3_path}")
            poser.OpenDocument(pz3_path)
            time.sleep(2)  # Wait to ensure document loads fully, may need ajustment for big scene files

            # Access the currently open Poser scene
            scene = poser.Scene()
            if scene is None:
                print(f"Warning: No scene found after opening {pz3_path}")
                continue
            print(f"Successfully accessed {pz3_path}")

            # Set render engine to Preview using SetCurrentRenderEngine
            scene.SetCurrentRenderEngine(poser.kRenderEngineCodePREVIEW)
            print("Render engine set to Preview.")

            # Set display style to Texture Shaded
            scene.SetDisplayStyle(10)  # 10 is Texture Shaded
            print(f"Display style set to Texture Shaded for {pz3_file}.")

            # Determine output path and base filename
            base_name, _ = os.path.splitext(pz3_file)
            output_folder = os.path.dirname(pz3_path)

            # Render each frame in the animation sequence to PNG
            num_frames = scene.NumFrames()
            for frame in range(num_frames):
                scene.SetFrame(frame)  # Set the current frame
                output_filename = f"{base_name}_{frame+1:04d}.png"  # e.g., filename_0001.png
                output_path = os.path.join(output_folder, output_filename)

                # Render the frame to the specified output path
                scene.Render()
                scene.SaveImage("png", output_path)
                print(f"Rendered frame {frame+1} to {output_path}")

            # Close the document without saving
            poser.CloseDocument()
            print(f"Successfully closed {pz3_file}\n")

        except AttributeError as attr_err:
            print(f"Attribute error while processing {pz3_file}{attr_err}")

        except Exception as e:
            print(f"Unexpected error while processing {pz3_file}{e}")



Learn the Secrets of Poser 11 and Line-art Filters.