Thu, Feb 13, 3:17 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: 2025 Feb 05 6:41 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: Name of the file PZ3


minuitdixhuit ( ) posted Wed, 15 December 2021 at 4:56 AM · edited Thu, 13 February 2025 at 3:01 AM

Hello,
Is it possible in a python script to get the name of the current PZ3 file?

Thanks for your help.

M18


structure ( ) posted Wed, 15 December 2021 at 6:56 AM · edited Wed, 15 December 2021 at 6:59 AM
Forum Coordinator
import poser
scene = poser.Scene()
document = scene.DocumentPath()
if document is None:
    document = "Untitled"

Locked Out


minuitdixhuit ( ) posted Wed, 15 December 2021 at 9:24 AM

Maaaaaaaaaaaaaaaaaaany Thaaaaaaaaaaaaaaaaaaaaaaaaaaaaanks !

Work fine !


structure ( ) posted Sat, 18 December 2021 at 9:06 AM · edited Sun, 19 December 2021 at 6:31 AM
Forum Coordinator

another way 

import poser
scene = poser.Scene()

def get_document(scene):
    return scene.DocumentPath() if not scene.DocumentPath() is None else "Untitled"

document=get_document(scene)

Locked Out


adp001 ( ) posted Sun, 19 December 2021 at 9:26 AM

structure posted at 9:06 AM Sat, 18 December 2021 - #4432058

another way 

import poser
scene = poser.Scene()

def get_document(scene):
    return scene.DocumentPath() if not scene.DocumentPath() is None else "Untitled"

document=get_document(scene)

Sorry for the " lecturer mode": but this is a good example of when you achieve a degradation with supposed code optimizations.

The function that returns the result is always called twice. Just to save one line of code.

The better (and more readable) way:

def get_document(scene):
  d = scene.DocumentPath()
  return d if d else "Untitled"

(In the end it's even less typed keys :))




adp001 ( ) posted Sun, 19 December 2021 at 9:42 AM

Ok, i missed that scene.DocunebtPath() can return None.

The last line should be:

  return d if d is not None and d else "Untitled"




adp001 ( ) posted Sun, 19 December 2021 at 10:01 AM

A test for None should always look like this:
  <statement> is None
or
  <statement> is not None.

But not:
  not <statement> is None

Why?

Once, because it is recommended by the Python documentation :).

And if you think about it, you will see that from <statement> the value is evaluated and then negated. The result is then checked for None (== None). If you write it correctly, the parameter is directly checked for != None. Which is of course more effective, and depending on what is behind <statement>, possibly also much faster.




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.