Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)
Failing that, dont parent but use the sphere to realign the figure as it rotates. Then delete the sphere. This tutorial may help also.
I've produced the following script but I'm not sure why it's not working as expected. My variables f2x and f2z always appear to be reporting as zero. Am I missing something? Is there an alternative way of getting the x and z co-ordinates?
<pre style="border:1px solid #000000;margin:2mm;padding:2mm;color:#000000;background-color:#f0f0f0;">
import poser
scene = poser.Scene()
fig = scene.CurrentFigure()
hip = fig.Actor("Hip")
foot = fig.Actor("Right Foot")
f1x = foot.ParameterByCode(poser.kParmCodeXTRAN).Value()
f1z = foot.ParameterByCode(poser.kParmCodeZTRAN).Value()
print f1x
print f1z
yrot = hip.ParameterByCode(poser.kParmCodeYROT).Value()
#Preserve IK settings (not sure how this works on models without IK)
ikl = fig.IkStatus(fig.IkNames().index('LeftLeg'))
ikr = fig.IkStatus(fig.IkNames().index('RightLeg'))
# Turn off
fig.SetIkStatus(fig.IkNames().index('LeftLeg'),0)
fig.SetIkStatus(fig.IkNames().index('RightLeg'),0)
# Rotate figure around hip
hip.ParameterByCode(poser.kParmCodeYROT).SetValue(yrot + 15)
# Move hip so that foot is back where it was
f2x = foot.ParameterByCode(poser.kParmCodeXTRAN).Value()
f2z = foot.ParameterByCode(poser.kParmCodeZTRAN).Value()
print f2x
print f2z
hx = hip.ParameterByCode(poser.kParmCodeXTRAN).Value()
hz = hip.ParameterByCode(poser.kParmCodeZTRAN).Value()
print hx
print hz
print hx+f2x-f1x
print hz+f2z-f1z
hip.ParameterByCode(poser.kParmCodeXTRAN).SetValue(hx+f2x-f1x)
hip.ParameterByCode(poser.kParmCodeZTRAN).SetValue(hz+f2z-f1z)
f2x = foot.ParameterByCode(poser.kParmCodeXTRAN).Value()
f2z = foot.ParameterByCode(poser.kParmCodeZTRAN).Value()
print f2x
print f2z
# Turn back on IK settings
fig.SetIkStatus(fig.IkNames().index('LeftLeg'),ikl)
fig.SetIkStatus(fig.IkNames().index('RightLeg'),ikr)
Quote - I've produced the following script but I'm not sure why it's not working as expected. My variables f2x and f2z always appear to be reporting as zero. Am I missing something? Is there an alternative way of getting the x and z co-ordinates?
The translation parameters are relative to the joint origin.
I fairly certain that you need to be using actor.WorldDisplacement()
The problem then is how to calculate the correct values to apply to the translation parameters for any given actor, which I think you can do by using the inverse of actor.WorldMatrix()
Ah ha. I think I've got it working now. The redrawing was also puzzling me but I've got that too.
<pre style="border:1px solid #000000;margin:2mm;padding:2mm;color:#000000;background-color:#f0f0f0;">
import poser
scene = poser.Scene()
fig = scene.CurrentFigure()
hip = fig.Actor("Hip")
foot = fig.Actor("Right Foot")
a = 15.0
f1 = foot.WorldDisplacement()
h = hip.WorldDisplacement()
yrot = hip.ParameterByCode(poser.kParmCodeYROT).Value()
#Preserve IK settings (not sure how this works on models without IK)
ikl = fig.IkStatus(fig.IkNames().index('LeftLeg'))
ikr = fig.IkStatus(fig.IkNames().index('RightLeg'))
# Turn off IK
fig.SetIkStatus(fig.IkNames().index('LeftLeg'),0)
fig.SetIkStatus(fig.IkNames().index('RightLeg'),0)
# Rotate figure around hip
hip.ParameterByCode(poser.kParmCodeYROT).SetValue(yrot + a)
# Move hip so that foot is back where it was
f2 = foot.WorldDisplacement()
hip.ParameterByCode(poser.kParmCodeXTRAN).SetValue(h[0]+f1[0]-f2[0])
hip.ParameterByCode(poser.kParmCodeZTRAN).SetValue(h[2]+f1[2]-f2[2])
# Turn back on IK settings
fig.SetIkStatus(fig.IkNames().index('LeftLeg'),ikl)
fig.SetIkStatus(fig.IkNames().index('RightLeg'),ikr)
# Refresh the screen
scene.Draw()
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.
I wish to rotate figure around the centre of their left foot rather than the centre of the hip. I appreciate that this can't be done easily through the user interface, my attempt looks like moon walking
http://uk.youtube.com/watch?v=huE0MRP6W-k
Would I be correct in thinking that this is possible via script. Has anyone already done this? I've found the maths but as I've never used python in poser before I'm not too sure where to start.
http://www.euclideanspace.com/maths/geometry/affine/aroundPoint/index.htm
Is the object model documented somewhere? Are there turtorials?