Forum: Poser Python Scripting


Subject: Render a real-time depth map, but how to turn the scene background white?

HartyBart opened this issue on Dec 13, 2023 ยท 3 posts


HartyBart posted Wed, 13 December 2023 at 4:44 AM

The script belowautomates the setup and rending of a real-time depth-map of a Poser scene, then reverts the changes to the scene. My question is about line 50, which opens the background color-picker for the user. There the user still needs to manually change the scene background color to white, then is expected to press 'OK'.  Is there some way to change the background color of a Poser scene automatically, by using Python code?

Result:



Code:

# Quickie depth map auto-render for Poser.
# Made December 2023.  Tested in Poser 13.

# From a saved Poser scene, auto render a quick real-time depth-map
# as a JPG on white, then revert the scene to the last saved scene file.

# The user only needs to change the output directory dirPath, and to
# choose the white colour for the background, when the script prompts for this.

import poser
import datetime

# Set up the saving and timestamp parameters. Change the save directory to suit your needs.
# Remember that the \\ double slashes are vital!!
dirPath="C:\\Users\\YOUR_USER_NAME\\YOUR_SAVED_FILES\\"
ext="JPG"
current_date = datetime.datetime.now().strftime ("%a-%d-%b-%Y-%H-%M-%S")

# Are we dealing with a Poser scene?
scene = poser.Scene()
# First, we make the Ground invisible. Thus, no ground shadows.

scene.SelectActor(scene.Actor("GROUND"))
scene.Actor("GROUND").SetVisible(0)

# Now we make sure the render is set to use a DPI of 300.
# And switch the render engine to real-time PREVIEW mode.
# This assumes the user has already set their preferred render size.
scene.SetResolution(3000)
scene.SetCurrentRenderEngine(poser.kRenderEngineCodePREVIEW)

# Now delete all lights in the scene. Then redraw the Poser scene.
lights = scene.Lights()
for light in lights:
    light.Delete()
scene.Draw()

# Now turn on the 'Smooth Shaded' display mode.
poser.ProcessCommand(1083)
scene.Draw()

# Now Toggle 'Depth Cue' display mode on.
poser.ProcessCommand(1044)
scene.Draw()

# Figure style is set to use document style, in case it doesn't for some reason.
poser.ProcessCommand(1438)
scene.Draw()

# Have the user set the scene's background colour to white.
poser.ProcessCommand(1269)

# Now we render the scene and save to a .JPG file. The filename is timestamped
# and saved into the user's preferred directory.
scene.Render()
scene.SaveImage(ext, dirPath + current_date)

# Done. Now we revert the entire scene, to its last saved state. This means
# that it doesn't matter that we changed display modes and deleted lights.
poser.ProcessCommand(7)



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