Mon, Nov 25, 8:31 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: Passing argument from "runPythonScript"


Medzinatar ( ) posted Fri, 26 May 2006 at 4:43 PM · edited Mon, 25 November 2024 at 6:34 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

  • Roni



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.

  • Roni



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 · edited Fri, 07 March 2008 at 2:08 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? 


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.