Wed, Nov 20, 9:20 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: 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: Update lights script - sometimes works, sometimes works a bit, sometimes doesn't


3dcheapskate ( ) posted Wed, 15 May 2013 at 7:44 AM · edited Tue, 22 October 2024 at 2:49 AM

If I create a simple scene with just two lights 'Light 1' and 'Light 2' and maybe a prop/figure the following script sometimes works (i.e. lights update correctly), sometimes partially works (i.e. light rotations update), and sometimes does nothing (haven't seen that recently, so maybe that's a red herring)

I've tried it in Poser 6, 8, and 9 and seem to get similar 'sometimes ok, sometimes not' problems. Poser 8/9 also has a problem with the 'Light Control' widget not updating unless I nudge something (e.g. camera trackball).

I'm sure I'm missing something obvious (as usual) but I can't see it for looking!

import poser

selcol = poser.DialogSimple.AskMenu('Set Lights','Select:',['Red','Green','Blue'])
if selcol == 'Red':
    rgb=[1.0,0,0]
    xyz=[90,0,0]
    str=0.5
if selcol == 'Green':
    rgb=[0,1.0,0]
    xyz=[0,90,0]
    str=1.0
if selcol == 'Blue':
    rgb=[0,0,1.0]
    xyz=[0,0,90]
    str=1.5
actlist = poser.Scene().Actors()
for act in actlist:
    if act.IsLight():
        if act.Name() == "Light 1":
            act.SetParameter("xRotate",xyz[0])
            act.SetParameter("yRotate",xyz[1])
            act.SetParameter("zRotate",xyz[2])                    
            tree = act.Material("Preview").ShaderTree()            tree.NodeByInternalName("Light").InputByInternalName("Color").SetColor(rgb[0],rgb[1],rgb[2])
tree.NodeByInternalName("Light").InputByInternalName("Intensity").SetFloat(str)
            tree.UpdatePreview()
        elif act.Name() == "Light 2":
            act.SetParameter("xRotate",-xyz[0])
            act.SetParameter("yRotate",-xyz[1])
            act.SetParameter("zRotate",-xyz[2])
            tree = act.Material("Preview").ShaderTree() tree.NodeByInternalName("Light").InputByInternalName("Color").SetColor(rgb[0],rgb[1],rgb[2])
tree.NodeByInternalName("Light").InputByInternalName("Intensity").SetFloat(str)
            tree.UpdatePreview()

poser.Scene().DrawAll()

 (and it's not bad indentation of the tree.NodeByInternalName lines, that's the forum)

I've reduced the problem I'm having to it's basics here - this is just a test script that simply allows the user to select one of three sets of parameters that define the colour, rotations and intensity for both lights.


The 3Dcheapskate* occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.

*also available in ShareCG, DAZ, and HiveWire3D flavours (the DeviantArt and CGBytes flavour have been discontinued).



3dcheapskate ( ) posted Wed, 15 May 2013 at 8:48 AM · edited Wed, 15 May 2013 at 8:50 AM

Cut-and-pasting the script as posted (and correcting the forum-induced indent/tab errors) I can't get it to fail at all now in Poser 8 or 9 (although I'll keep trying - I know it did fail before!)

But in Poser 6 a pattern seems to be emerging:

  • If I stay in the Pose room the intensities/colours are never set correctly when I run the script, regardless of whether either of the lights are selected
  • If I have one of the lights selected and THEN go to the Material room and run the script, the selected light is updated correctly, but the other light only has rotations set correctly.
  • But if I do File > New, go straight to the Material room, select either light, and run the script, BOTH lights are updated correctly

Can anybody explain the Poser 6 effect, and (more importantly) how to get round it?

And if anybody else gets it to fail in Poser 8/9 can you let me know?


The 3Dcheapskate* occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.

*also available in ShareCG, DAZ, and HiveWire3D flavours (the DeviantArt and CGBytes flavour have been discontinued).



3dcheapskate ( ) posted Wed, 15 May 2013 at 9:22 AM · edited Wed, 15 May 2013 at 9:23 AM

I think I've found the conditions for the "Poser 8/9 'Light Control' widget not updating unless I nudge something (e.g. camera trackball)" problem. It seems to occur if I call my Python script from a PP2 file, like this (which is the way I want to do it):

{
version
    {
    number 6
    }
runPythonScript ":Runtime:Python:poserScripts:3DCheapskate:WorldBall:WorldBallSetup.py"
}

Calling it directly via File > Run Python Script the problem doesn't seem to occur. But can anybody suggest WHY this would be?


The 3Dcheapskate* occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.

*also available in ShareCG, DAZ, and HiveWire3D flavours (the DeviantArt and CGBytes flavour have been discontinued).



3dcheapskate ( ) posted Wed, 15 May 2013 at 9:43 AM

...btw, the "Poser 8/9 'Light Control' widget not updating unless I nudge something (e.g. camera trackball)" problem looks like it's only the ROTATIONS not updating - the colours and intensities seem correct.


The 3Dcheapskate* occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.

*also available in ShareCG, DAZ, and HiveWire3D flavours (the DeviantArt and CGBytes flavour have been discontinued).



3dcheapskate ( ) posted Wed, 15 May 2013 at 10:48 PM · edited Wed, 15 May 2013 at 10:55 PM

Just found another clue for the Poser 6 problem - it only happens if I haven't yet done a render. So here's a summary - two distinct problems:

PROBLEM 1: Poser 6 (doesn't seem to happen in Poser 8/9)

If I haven't done a render and I haven't been to the Material room (It's actually a tiny bit more complex - see my second post) then the colour/intensity aren't updated (although script debug indicates they have been). Rotations are okay. This happens whether the script is run directly (File > Run Python Script) or from a PP2.

Workaround: Do a render (or go into the Material room with a prop/figure, but not one of the lights, selected and return to the Pose room) before running the script

PROBLEM 2: Poser 8/9 (doesn't seem to happen in Poser 6)

If I call my script directly (File > Run Python Script) it's fine, but if I call it from a PP2 the ROTATIONS aren't automatically updated on the Light Control widget (as mentioned in the two previous posts). Colour/intensity are okay, and rotations are actually correct - it's just the widget display

Workaround: Nudge the camera trackball and the Light Controls update

 

I'm still puzzled by the WHY? and would like to solve this within the script if possible, but with the workarounds mentioned above the problems are only minor irritations now.


The 3Dcheapskate* occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.

*also available in ShareCG, DAZ, and HiveWire3D flavours (the DeviantArt and CGBytes flavour have been discontinued).



3dcheapskate ( ) posted Thu, 16 May 2013 at 9:54 PM

file_494495.png

Well, even though nobody's replied yet, simply finding words to try and explain the problem to others helped clarify things. And since I now have criteria for the problems, I can tell within the script when the problem is LIKELY to occur (even though I can't tell if it actually HAS occurred). So I can simply prompt the user with the workarounds like this:

For prompting user with workarounds for known problems

criteria = False
poserversion = poser.AppVersion()
    
...

If using Poser <9 and we met the colour/intensity problem criteria give the user the workaround

if criteria and int(poserversion[0]) < 9:
    poser.DialogSimple.MessageBox("...workaround message here...")
    

If using Poser >6 give the user the workaround

if int(poserversion[0]) > 6:
    poser.DialogSimple.MessageBox("...workaround message here...")

It's not an ideal solution, but if anybody else runs into apparently insoluble PoserPython problems it's an approach worth considering (screenshot of my two workaround dialogues attached).

P.S. I'm still very interested in the WHY? so if anybody has any ideas... A proper solution would be better than my workaround.


The 3Dcheapskate* occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.

*also available in ShareCG, DAZ, and HiveWire3D flavours (the DeviantArt and CGBytes flavour have been discontinued).



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.