Forum: Poser Python Scripting


Subject: About select body part of object file by python

Tekitoumen opened this issue on Aug 26, 2022 ยท 7 posts


adp001 posted Wed, 31 August 2022 at 10:13 AM

What you see there are polygon groups. These groups were created when you exported your figure. That's why they have the same name as the body parts. From these polygon groups you can actually restore the figure (at least vertices and polygons in the right order).

To get the vertices you are interested in, you have to analyze the polygons and extract the data you need from them. Poser Python has a few commands for this:

Example:

geom = poser.Scene().CurrentActor().Geometry()
polys = geom.Polygons()
bodypart_name = "chest"

for poly in polys: # type: poser.PolygonType
if poly.InGroup(bodypart_name):
for vert in poly.Vertices(): # type: poser.VertexType
print(vert.X(), vert.Y(), vert.Z())


"poly.InGroup(<str>)" tells you if the queried polygon belongs to the group you are looking for.

"poly.Vertices()" returns a list of Poser's vertex objects (poser.VertexType). A Poser vertex knows X(), Y() and Z() to query as well as the corresponding "set" functions (SetX(), SetY(), SetZ()).

Another example:

sets = geom.Sets()
vertices = list()
for poly in geom.Polygons(): # type: poser.PolygonType
if poly.InGroup(bodypart_name):
index_start = poly.Start()
index_end = poly.Start() + poly.NumVertices()
vertices.append(sets[index_start:index_end])


Here the indices are queried into the geometry's vertex array and stored in the "vertices" list. This can only be done using the "sets" (geom.Sets()), which provide pointers into the vertex array.