Forum: Poser Python Scripting


Subject: Making a conforming garment

Anthony Appleyard opened this issue on May 26, 2018 ยท 3 posts


Anthony Appleyard posted Sat, 26 May 2018 at 10:59 AM

When making a conforming garnent, one tedious job is copying all relevant origins and endpoints to the garment from whatever it conforms to. For that purpose, I wrote this Python script. Please test it and comment on it

import poser
import string
import os
import sys

def findactor(fig,fn):
    if fig==None:
        return None
    acts1=fig.Actors()
    for ac1 in acts1:
        if ac1.InternalName().startswith(fn):
            return ac1
    return None

scn = poser.Scene()
act = scn.CurrentActor()
fig=act.ItsFigure()
if fig == None:
    print "I am starting at a ",act.Name()
    raise("I need to be on a character, or a prop owned by a character")
else:
    print "I am starting at ",fig.Name(),"'s ",act.Name()
acts=fig.Actors()
cfig=fig.ConformTarget()
if cfig==None:
    print fig.Name(),"is not a conformer."
    raise("error")
else:
    print fig.Name(),"conforms to",cfig.Name()
cacts=cfig.Actors()
for act in acts:
    na=act.InternalName().split(':')[0]+':'
    print "testing",act.InternalName()
    if na=="CenterOfMass:": continue
    if na=="GoalCenterOfMass:": continue
    print "checking",fig.Name(),"'s",na
    ca=findactor(cfig,na)
    if ca==None:
        print "not found",cfig.Name(),"'s",na
        continue
    print "conforming",fig.Name(),"'s",act.Name(),"to",cfig.Name(),"'s",ca.Name()
    (ox,oy,oz)=ca.Origin()
    (ex,ey,ez)=ca.EndPoint()
    act.SetOrigin(ox,oy,oz)
    act.SetEndPoint(ex,ey,ez)
    print "set origin to",ox,oy,oz,", endpoint to",ex,ey,ez
poser.ProcessCommand(1559)
#scn.DrawAll();

FVerbaas posted Fri, 15 June 2018 at 12:18 PM Forum Coordinator

OK making my way back into the Python range. One question is how you handle the exceptions you raise. Those make Pyhon exit?


Anthony Appleyard posted Sun, 22 July 2018 at 5:24 AM

To FVerbaas: By letting the raise instruction display its message and then exit.