Forum: Poser Python Scripting


Subject: Passing argument from "runPythonScript"

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


Medzinatar posted Fri, 26 May 2006 at 4:43 PM

I used "runPythonScript" to execute a ".PY" file  from a ".PP2" but I can't figure out how to pass an argument along with it or for that matter how to read one if I did.  Any help appreciated



nruddock posted Fri, 26 May 2006 at 5:53 PM

I'm pretty certain that there isn't any way to pass arguments in the PP2 file.

If there was you'd find them in the sys.argv list.
Poser does actually set argv[0] to the filename of the script.

One way round this would be to use a number of small scripts that just call a method with different arguments.
The method that actually does the work would be in another PY file, the calling scripts would need to import it.


Medzinatar posted Fri, 26 May 2006 at 8:54 PM

Thanks for the help on this one.  This one is going to be so infrequently used it is just as easy to hard code it for each instance.



PoseWorks posted Sat, 27 May 2006 at 9:55 AM

You can "pass arguments" using Animation Sets, provided that you're using a CM2, MC6 or PZ3. This is how ShaderSpider's FX-MATs work.


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.

 


dburdick posted Fri, 07 March 2008 at 2:23 AM

Oops,

I copied some errant code for the Python Script.  Here's the correct one:

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 = Args.Name().split("_") # Split argument params
       ArgList.remove("PYT")   # Remove the dummy prefix from the ArgList
       Args.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


markschum posted Fri, 07 March 2008 at 11:08 AM

You can also add some  parameters to a figure, prop or null and retrieve them .

actor.CreateValueParameter(etc)


dburdick posted Fri, 07 March 2008 at 2:10 PM

Quote - You can also add some  parameters to a figure, prop or null and retrieve them .

actor.CreateValueParameter(etc)

Sounds like an intriguing alternative.  How would you do this via a mat pose injection (.pz2) file?