Wed, Nov 20, 7:51 AM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



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


HartyBart ( ) posted Wed, 13 December 2023 at 4:44 AM · edited Wed, 20 November 2024 at 1:01 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:

jvDeCsnreP3Phh35XrTnRDpw0QQ2d5oAofDobLDl.jpg


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.


bwldrd ( ) posted Thu, 14 December 2023 at 8:32 AM · edited Thu, 14 December 2023 at 8:36 AM

scene.SetBackgroundColor (1.0,1.0,1.0) .. this is from the poser 11 Poser Python Methods Manual.pdf, but still works in 13.

--------------------------------------------------------------------------------

Consider me insane if you wish, but is your reality any better?


HartyBart ( ) posted Thu, 14 December 2023 at 2:14 PM

Wonderful, many thanks Bwldrd. I had run several searches for "background" across my Poser Python folder, but didn't think to search for SetBackground.

Here is the final working fully-automated script, tested on both Poser 11 and 13.  Useful for those needing a quick depth pass render, but who not want to go to the trouble of setting up an Atmosphere, using a special .MT5, or rendering in Firefly to .PSD with z-buffers on.


# Make a quick depth-qued auto-render from Poser.
# Version 1.0 - December 2023.  Tested in Poser 11 and 13.
# With thanks to bwldrd for the 'SetBackgroundColor' tip.

# 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.

NOTE: The user will needs to change the output directory 'dirPath=' to their chosen path.

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!! This is for Windows. Mac paths may be different?
dirPath="C:\\Users\\WINDOWS_USER_NAME\\FOLDER_NAME\\"
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 or grid.
# Comment out these two lines with #'s if you dont want this to happen.
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 now set to use document style, in case it wasn't for some reason.
poser.ProcessCommand(1438)
scene.Draw()

# Set the scene's background color to white.
scene.SetBackgroundColor (1.0,1.0,1.0)
scene.Draw()

# Now we render the scene in Preview at 300dpi and save to a .JPG file.
# It must be .JPG otherwise we get a .PNG cutout with alpha and fringing.
# The file 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 the display modes and deleted lights.
poser.ProcessCommand(7)



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.