Thu, Jan 30, 3:52 PM 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 Dec 02 3:16 pm)

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: About select body part of object file by python


Tekitoumen ( ) posted Fri, 26 August 2022 at 3:00 AM · edited Thu, 30 January 2025 at 3:42 PM

Hello.


https://www.renderosity.com/forums/threads/2972020/reduce-the-number-of-meshes#msg4441239


I was taught how to output an obj file with body part names etc. at this URL.


I don't know how to select this body part from python after importing this obj file. .

Could you tell me how to realize it from python? (For example, which method should be used, etc.)


Thank you.




FVerbaas ( ) posted Sun, 28 August 2022 at 9:11 AM · edited Sun, 28 August 2022 at 9:19 AM
Forum Coordinator

So, you load a prop from file and you want to do something with that prop via Python?

If you know the name of the prop you can use scene.Actor()

The prop usually will be selected after the loading so you can also use scene. CurrentActor()



adp001 ( ) posted Mon, 29 August 2022 at 2:31 PM

After the above procedure, there are no more individual body parts. The geometry is baked together and is a single, solid object (a "Prop").

Unlike most other programs, a figure in Poser is not one continuous mesh but is made up of various body parts that are handled so that the whole thing looks like one solid figure.

So if you want to use what you've produced as a Poser figure again, you first have to disassemble it and tell Poser which parts of the prop belong to which "body part".




Tekitoumen ( ) posted Tue, 30 August 2022 at 2:18 AM

Thank you for your reply.

I was able to understand.


If I import the model expoted obj model again, the model will be treated as props.


I noticed that this prop contains a body part in a group.


#test_model.obj imported

actor = scene.Actor("test_model")

actGeom = actor.Geometry()

print(actGeom.Groups())


----result----

['hip', 'abdomen', 'chest', 'lThigh', 'lShin', 'lFoot', 'neck', 'head', 'lCollar', 'lShldr', 'lForeArm', 'lHand', ' rThigh', 'rShin', 'rFoot', 'rCollar', 'rShldr', 'rForeArm', 'rHand']


What I want to do now is get the coordinates of just the "hip" part, for example. (act Geom.Vertices())


Is it possible to select only one part in the group and get the vertex coordinates limited to that part?

Which method will be used?


Thank you all for your kindness.



adp001 ( ) posted Wed, 31 August 2022 at 10:13 AM · edited Wed, 31 August 2022 at 10:15 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.





adp001 ( ) posted Wed, 31 August 2022 at 11:20 AM

In the last example it is better to use "extend" instead of "append" to avoid a list within a list (last line).




Tekitoumen ( ) posted Wed, 14 September 2022 at 8:11 PM

Sorry about the late reply.

I was able to solve it thanks to you.

I was able to choose from pythons for each body part.


Thank you very much. Thank you for your kindness.


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.