Forum: Poser Python Scripting


Subject: Passing argument from "runPythonScript"

Medzinatar opened this issue on May 26, 2006 · 8 posts


dburdick posted Fri, 07 March 2008 at 1:58 AM

I came up with a sneaky way to do this.  What you do in the pose file preceeding the python script call is to rename the scene "GROUND" object to an argument string and then when you call your Python script, parse the name of the "GROUND" object to extract an argument list.  Here's an example.

The .pz2 file:

{
version
     {
     number 6
     }
actor GROUND:1
     {
     name PYT_Specular_Moist
     }
}
{
version
    {
    number 6
    runPythonScript ":Runtime:Python:poserScripts:SkinVue:Test.py"
    }
}

The Python script:

import poser

ArgList = 0

try:
     Args = poser.Scene().ActorByInternalName("GROUND")  # Get Ground Actor 
     if Args.Name().startswith("PYT"):      # Parse if it starts with PYT prefix
           ArgList = GroundActor.Name().split("_")    # Split argument params
           ArgList.remove("PYT")        # Remove the dummy prefix from the ArgList
           GroundActor.SetName("GROUND")      # Rename the Ground actor back to its original Name
except:
     pass             # No ground actor object found in scene

Begin normal program processing

if ArgList:
      print ArgList

I think this will work in most cases as long as the scene contains a GROUND actor which almost all do.  In this particular example, it strips two arguments Specular and Moist.  I use a prefix of PYT (e.g. Python Trojan) as an identifier and then remove it from the ArgList.   At the end, I rename the GROUND actor back to it's original name "GROUND".  I think it will support stuffing 32 characters in the string - good enough to get a couple of args at least.