Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)
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.
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
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.
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
if ArgList:
print ArgList
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.
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