Python Basics

Here I'm going to attempt to put together some basics of Poser Python (as I discover them).

First of all, you have to tell Python to use the poser extensions, so all Poser scripts start with

import poser
This sets up all of the Posere elements and functions (or methods) that you can use to control Poser and your scene.

The first concept you need to understand in PoserPython is the pointer. In just about every script, pointers are used make the script more readable, and to shorten code. The following line stores the internal name of the first figure in a scene in the variable 't'.

t=poser.Scene().Figures()[0].InternalName()
Every element in your Poser scene is part of the poser.Scene() object. Within than, the figures are listed in the Figure() method. PoserPython provides you with a variety of tools to change figures and to retrieve information about them, and those methods are added to the end of one of the different ways of selecting a figure.

Pointers are used to simplify this. The second line of code in most scripts will be:

scene=poser.Scene()
This line does not copy your scene into the scene variable. Instead, it creates a pointer that you can use instead of poser.Scene(). With this in place, our first line of code now becomes
t=scene.Figures()[0].InternalName()

Methods of indicating a figure

Each figure in a Poser scene has a unique identifier created by the program. Luckily, You never need to directly use this identifier, as it refers to the location in memory of the figure.
import poser
scene=poser.Scene()
print (scene.Figures())
print (scene.Figures()[0])
print (scene.CurrentFigure())
Type in this short script, create a scene, add a couple of figures, then run the script. Python will print out three lines. The first will print out one location for each figure in the scene.
<Figure object at 0x02208AD8>, <Figure object at 0x02CEAC28>
There are several interchangable ways of pointing at a particular figure. If you know the name of a figure then you can use
scene.Figure('Figure Name')
If you know you want the first figure in a scene, you could use
scene.Figures()[0]
If you want the current figure, use
scene.CurrentFigure()
In each case, the result is 'Figure object at 0x00000000'. Why is this import you may ask? Simple: Whenever a Python method asks for a Figure, Actor or Material object, what it wants is the object reference, NOT the name of a figure, actor or material. Thus, the first line of code will fail:
scene.CurrentFigure().SetConformTarget('posette')
Would fail, while
scene.CurrentFigure().SetConfromTarget(scene.Figure('posette'))
Would. The following piece of code will list all of the figures in your scene, as a list of object locations.
import poser
scene=poser.Scene()
print (scene.Figures())

Figure(), Actors(), Materials()

For name in list

Python gives you an easy way of working through a list of figures, actors or materials.
import poser
scene=poser.Scene()
for thisFigure in scene.Figures():
    print (thisFigure.Name(), thisFigure.GeomFileName())
For every figure in your scene, this code repeats, printing out the figure name and geometry file. thisFigure is set to scene.Figures()[0] for the first figure, scene.Figures()[1] for the second, and so on until it runs out of figures.

PoserWorld