Fri, Nov 29, 9:52 PM 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: Is there a batch render script for Pz3 thumbnails?


z ( ) posted Thu, 02 April 2009 at 5:18 PM · edited Fri, 29 November 2024 at 9:50 PM

I can’t be the first guy to want this:

 

I want to be able to render PNG thumbnails for PZ3 scene files, en masse. I have D3D’s batch render script and its close but, here’s what I need:

 

  1. to be able to open a Pz3 file (preferably from an external list of filenames).

  2. Set the rendersize to 91x91

  3. Do a down and dirty P4 (non firefly) render, and save it (same path, same name .png)

 

Then go to the next file.

 

Seems pretty simple. One other thing, I’d love it to be fault tolerant. If it finds a missing object or texture, it should just skip it and render what it can find.

 

Does this (or something like it) exist somewhere?  

 

I’m VB coder and not a Python coder, but if I saw the right examples I could probably cut and paste something together. The D3D “Render Scene” script opens and saves, but it only renders in firefly, and I have no idea how to set rendersize.

 

Aha tia
z


PhilC ( ) posted Thu, 02 April 2009 at 7:03 PM

This may help.
http://www.philc.net/forum/viewtopic.php?t=2572

You just need to add a "for file in directory" loop

See the "walk" and "visit" sections in Poser 7RuntimePythonposerScriptsscripsMenuUtilityuncompressPoserFiles.py


z ( ) posted Tue, 07 April 2009 at 9:50 AM

Sorry man,

I tried. but no...
python scripting and VB are just too different. What's all this

{
    bracketing
}

about? couldn't you all just use {bracketing}?

I don;t get it. And no I can't cut and paste that stuff together. Although that looks like what was looking for...

z


markschum ( ) posted Tue, 07 April 2009 at 10:43 AM

I will try to put something together for you.

set render options
get folder name
get file list for folder
for each file in list
   load file
   render file
   save render to same folder

with some tests to check if render completed ok.
I dont think you can error trap the render if files are not found but I will check

Python is indent sensitive , it uses indentation to determine what code is to be executed.

Theres some good introductory stuff on the python.org website.


markschum ( ) posted Tue, 07 April 2009 at 1:42 PM

file_428127.txt

crude batch render script attached.

This gets pz3 file names from ONE folder thats coded in the script
and renders using P4 renderer to image size also coded in the script.
Saved as a png file in the same folder with same name as the scene file.

You should be able to make the needed changes , just observe the format I used for the path.


z ( ) posted Wed, 08 April 2009 at 6:01 PM

Quote - I will try to put something together for you.
Python is indent sensitive , it uses indentation to determine what code is to be executed.

Thanks for your help.

indent sensitive?!   Really ?

In VB indents (and caps) are just a user convenience. They have no effect in code.

(I am so never going to learn this language.)
thanks again
z


nruddock ( ) posted Wed, 08 April 2009 at 7:03 PM · edited Wed, 08 April 2009 at 7:07 PM

Quote - (I am so never going to learn this language.)

Learing Python (the language) is easy.

Learning to use Python as implemented in another program depends on how the creators chose to do the integration.

The best way to get used to the indentation thing is to use a Python aware editor, such as idle, which comes with the standard Python distribution.


markschum ( ) posted Wed, 08 April 2009 at 10:20 PM

You get nice error messages when you mess up the indenting. 
Dont try learning python from the Poser python methods manual , it really doesnt explain enough. Go to python.org and get the python manuals , and look at a few existing scripts. If you can manage basic , python isnt much harder.


z ( ) posted Fri, 10 April 2009 at 11:04 AM

Quote - crude batch render script attached.

This gets pz3 file names from ONE folder thats coded in the script
and renders using P4 renderer to image size also coded in the script.
Saved as a png file in the same folder with same name as the scene file.
You should be able to make the needed changes , just observe the format I used for the path.

Thanks man that script is almost perfect. I’ve been trying it out.

 A few things though:

 If there’s already a PNG file, it will overwrite it. That’s a problem because I’ve already manually done about half the icons. (so it either needs to take a file list, or skip Pz3s if it finds PNGs)

I keep getting a “Poser is out of memory” message, but then it seems to work anyway.

If it can’t find a PSD file, it renders a big solid colored square (way bigger than 91x91) (and the other missing files are a pain) 

And (proudly) I’ve been able to make some changes myself: it takes soo long to load all the textures, it might as well do a Firefly render. And I changed the size to 300 square,too

 Thanks again
z


markschum ( ) posted Fri, 10 April 2009 at 11:50 AM

indeed yes, the check for existing file is easy enough to add but the rest of it as far as I know cant be trapped.  There is a close document at the end which is an attempt to get Poser to discard textures and clear some memory though I dont know if its working.

This is just my typical brute force programming :)   


markschum ( ) posted Fri, 10 April 2009 at 2:39 PM

file_428340.txt

Have a look at this one. It should test for the output render name and skip the file if it exists.

its a simple if not os.path.exists(filename): test but you then have to indent everything thats dependant on the condition.


z ( ) posted Mon, 13 April 2009 at 12:17 PM · edited Mon, 13 April 2009 at 12:19 PM

Quote - Have a look at this one. It should test for the output render name and skip the file if it exists.

its a simple if not os.path.exists(filename): test but you then have to indent everything thats dependant on the condition.

Um, I see the if not statement...
if not os.path.exists(cfo):
   
but it's still overwriting files, how is that?

I can make a list of the right files
maybe just hardcoding the filepaths would be easier
z


Rocketship3D ( ) posted Thu, 07 May 2009 at 9:07 AM

Hi everyone,

Ben Margolis here, from Rocketship Software, makers of PzDB.

I’ve been watching this thread because we have had several requests to have PzDB index Pz3 files too. And if we’re going to do that, we’re going to need something very much like this script.

 So Z, I’ve found the bug you found in that If statement. (he forgot to add the file path to the name)

So that line should be:

 if not os.path.exists(myfilepath + cfo):

And as you requested here’s a version that lets you enter any list of files, instead of doing whole directories:

import poser
import os

 

myq = []
myq.append ("E:PoserFilesCharactersDaveX1File1.pz3")
myq.append ("E:PoserFilesCharactersDaveX1File2.pz3")
myq.append ("E:PoserFilesCharactersDaveNew FolderFile3.pz3")
#add more files here

**
**#and then render them all

mql = len(myq)print "Rendering a possible " + str(mql) + " pz3 files."

process each file in the list

for cf in myq:     

create output name

            cfo = cf[0:-4] + ".png"
            cfd = cf
            if not os.path.exists(cfo):
                        # open the scene file
                        print "Processing File: " + cfd
                        poser.OpenDocument(cfd)
                        # get the scene and set render type , output size
                        scn = poser.Scene()
                        scn.SetCurrentRenderEngine(poser.kRenderEngineCodeFIREFLY)
                        scn.SetOutputRes(300,300)
                        scn.SetFrame(0)
                        # render the scene
                        print "Rendering: "+ cfd
                        prr = scn.Render()
                        print prr          
                        # save the image , same path, as png
                        print "Saving image as: " + cfo
                        scn.SaveImage("png", cfo )
                        # and close the document

                        poser.CloseDocument(1)

print "done"

close Poser down

poser.Quit()

 

markschum, If you wouldn’t mind I’d like to use this as a starting point for a Script that we include in the next PzdDB.  It’ll need better error handling though, and I’d love a GUI window with a cancel button, any idea about how to do that? 

Ben Margolis
Rocketship Software


markschum ( ) posted Thu, 07 May 2009 at 11:02 AM · edited Thu, 07 May 2009 at 11:07 AM

Sure, use what you like. I dont do any commercial python work so I have no need to protect my stuff.  I would be peeved if someone took a script and sold it without changes but to be commercial you need lots of error trapping.    There are some dialog options in poser 7 and maybe 6 , otherwise you need to use tkinter which is just nasty in my limited experiance. ;)   

There are several python guys who could do this easily, maybe one of them would be interested in a collaboration.

Just a point but the character in a string indicates a control character and will usually blow up. Best to use / or   in path names.


z ( ) posted Wed, 13 May 2009 at 6:07 AM

Thanks guys.

This one works great. (as long as I use )


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.