Wed, Dec 25, 4:53 PM CST

Renderosity Forums / Poser 13



Welcome to the Poser 13 Forum

Forum Moderators: nerd, RedPhantom

(Last Updated: 2024 Dec 22 2:27 pm)



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


tnpir4002 ( ) posted Mon, 30 September 2024 at 4:45 PM · edited Wed, 25 December 2024 at 2:32 PM

Simple enough request, but the reality of it is proving to be problematic. Short and sweet: is there any way to batch render the PZ3s in a folder and export MP4s of all of them with specific settings?

I've been trying all day to come up with a Python script that will do it, but no matter what avenue I try I just get a faceful of errors. Has anyone else tried this? Or is there another method that I'm not seeing?


HartyBart ( ) posted Thu, 24 October 2024 at 3:57 PM · edited Thu, 24 October 2024 at 4:01 PM

D3D's "Render Scenes" script shipped with Poser 11 as standard. From the readme: "'Render scenes' is a batch render[er] for several scene files". Only for images, but the script is in plain text and hackable Python, and looks at first glance like it could be made to do what you want with a little hacking. 

It was not included in Poser 13.  Needs WX for its UI, and I vaguely recall that Apple banned WX on Macs (along with so much else)? So perhaps, 'Windows only'?

fvGACm1nwT3iDpOpvsk8WNyZZxQCMtq8bhXOJxQ9.jpg


This simple Poser script for rendering a frame from multiple mo-cap files looks like it has some interesting code  ... https://gist.github.com/erfannoury/76c839b96ebd17aa2102




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


tnpir4002 ( ) posted Thu, 24 October 2024 at 4:03 PM

Considering I HAVE Poser 11 you'd think I'd have realized this...looks like it didn't ship with Poser 12 either so I don't feel quite so bad. This is a GREAT tip though and I really appreciate it!!!


HartyBart ( ) posted Fri, 25 October 2024 at 8:42 AM
Glad to be of help. If you do hack out a workable version for MP4 output with consistent settings-loading for each file, could you post the details for others? Or perhaps the entire script?



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


tnpir4002 ( ) posted Fri, 25 October 2024 at 9:07 AM

If I can figure it out I definitely will!


nerd ( ) posted Sat, 26 October 2024 at 5:02 PM · edited Sat, 26 October 2024 at 5:03 PM
Forum Moderator

Sadly, Raif Sesseler the person behind D3D passed several years ago. We tried to acquire the rights and code from his estate. No one handling his affairs seemed to be able to do this. That's why it was left out of Poser after P12. We don't have the rights to distribute it.


HartyBart ( ) posted Sun, 27 October 2024 at 11:15 AM

Ah, well here is D3D's 2008 "Three Poser Python scripts to set up FireFly renders and to batch render poses and scenes", posted by the man himself on Renderosity Freestuff, and flagged by him as "licensed for commercial or non-commercial use". https://www.renderosity.com/freestuff/items/51547/render-11  Includes renderscenes.py

Presumably, given the permissive licence, this could now be forked and 'tickled up a bit' to work for Poser 14 (I recall it didn't work in Poser 11)? The script itself does say simply "copyright" in the header, but presumably his later posting of the script(s) under a permissive licence voids that?



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


tnpir4002 ( ) posted Sun, 27 October 2024 at 11:33 AM

I didn't crack the code for MP4s, but thanks to ChatGPT I did get this to work exactly as I need it to with Poser 12 for PNG sequences. Turns out this is a better solution for what I'm doing anyway, since the Preview engine can't render proper alpha channels in Silhouette mode. AfterEffects is able to import the PNGs as a PNG sequence and treat them exactly as they would an MP4, which for my purposes works precisely the way I need.

Code:

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


            # Access the current 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}")



HartyBart ( ) posted Sun, 27 October 2024 at 12:08 PM

Here is a some PoserPython and Poser-specific code for MP4s which may be useful...

# MOVIE STUFF. First we initialize the movie.
moviemaker = scene.MovieMaker()
# Set movie output format to PREVIEW.
moviemaker.SetMovieRenderer(poser.kRenderEngineCodePREVIEW)
# Set movie frame-rate of 15 FPS, plus an increment of one frame (i.e. render all frames)
moviemaker.SetFrameOptions(151)
# Remove jaggies, make it nice and smooth.
moviemaker.SetAntialias(1)
# For Poser 11, code 2 = make a MP4 movie with standard codec.
moviemaker.SetMovieFormat(2)
# Give our rendered movie a path and name.
moviemaker.MakeMovie(r"C:\folder\movie_file.mp4")



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


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.


Privacy Notice

This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.