![]() |
|
Python Lists |
| Home | Tutorial Links | My Tutorials | Freebies |
All the code samples in this tutorial assume that your script starts with
import poser scene=poser.Scene()Lists of objects appear at different levels of your Poser scene. At the level of the scene, you have
scene.Actors() scene.Figures() scene.Cameras() scene.Lights()In this list, scene.Actors() contains a list of all actors not part of a figure, scene.Figures() gives you all of the figures in a scene, while the Cameras and Lights are treated in the same way as actors, so most methods that work for Actors also work for Cameras and Lights.
Other lists appear as part of an individual object.
scene.Figures().Actors() scene.Figures().Materials() scene.Actors().Materials() scene.Actors().Parameters()Anything that works for scene.Actors() should also work for scene.Figures().Actors(), so
scene.Figures().Actors().Materials()Would return a list of Materials, organised by actors within figures. The following piece of code should print out a list of body parts in the current figure, with lists of parameters
import poser scene=poser.Scene() for eachActor in scene.CurrentFigure().Actors(): print (eachActor.Name()) for eachMat in eachActor.Parameters(): print (eachMat.Name())This piece of code introduces a key python technique - the for in loop. This loop will run as many times as there are elements in a list, setting the loop variable to the value of each item in the list. In the code
for eachActor in scene.CurrentFigure().Actors():the loop will repeat for each actor in current figure. The first time though the loop, eachActor will be set to scene.CurrentFigure().Actors()[0], then to scene.CurrentFigure().Actors()[1], and on until there are no more actors.
eachActor can then be used with any actor method, so eachActor.Parameters() is the same as poser.Scene().CurrentFigure().Actors()[0].Parameters(). If the list is empty, then the loop will not run.