Forum: Poser Python Scripting


Subject: Callback created using parm.SetUpdateCallback() not behaving as expected

3dcheapskate opened this issue on Sep 25, 2021 ยท 16 posts


3dcheapskate posted Sun, 03 October 2021 at 11:13 PM

HA !

I spoke too soon ! 

Try this...

(This script sets the xTran and zTran of the selected figure's Body based on its yRotate, using the bog-standard right-angle triangle sine/cosine mathemagical stuff to move the figure in a circle. Not quite what I was trying to do, but it highlights one of my major misunderstandings about callbacks, and gives a clue as to how I should be doing it.)



# ! Callback Test Setup Version 582

import math


# I spotted this technique in C:\Program Files\Poser Software\Poser 11\Runtime\Python\poserScripts\SampleCallbacks\muscleMag.py

# 1) Do NOT try and modify parameter B from a parameter A callback

# 2) Instead, create a callback for parameter B and use parameter A there to do the required calculation

# 3) Parameter B does NOT have to change for the parameter B callback to be called.


# INSTRUCTIONS FOR RUNNING TEST

# -----------------------------

# 1) Load any figure and ensure its body is selected

# 2) Increase the frame count from 30 to 360

# 3) Go to frame 360 and set yRotate to -360 (yRotate increases anticlockwise when viewed from above, I want this to go clockwise)

# 4) Change camera to top view and zoom out a bit, enough to see a circle of radius 1PNU around the worldorigin.

# 5) Slide the frame counter back and forth a few times - the figure should rotates about its origin

# 6) Set the frame counter back to frame 1

# 7) Run this script

# 8)Slide the frame counter back and forth a few times - the figure will rotate along a circle radius 1PNU centred at the origin.


# Callback for the "yRotate" parameter

def cheapskatesYRotateCallback(parm,value):

return value % 360 # Go round in a circle


# Callback for the "xTran" parameter

def cheapskatesXTranCallback(parm,value):

return value - (onestep*math.sin(math.radians(parmYRot.Value())))

# Callback for the "zTran" parameter

def cheapskatesZTranCallback(parm,value):

return value - (onestep*math.cos(math.radians(parmYRot.Value())))


global parmYRot

global parmXTran

global parmZTran

global onestep


body=poser.Scene().CurrentFigure().ActorByInternalName("BODY")

parmYRot=body.Parameter("yRotate")

parmXTran=body.Parameter("xTran")

parmZTran=body.Parameter("zTran")

onestep=1.0

print "Setting up the 'yRotate' callback..."

poser.Scene().CurrentActor().Parameter("yRotate").SetUpdateCallback(cheapskatesYRotateCallback)

print "Setting up the 'xTran' callback..."

poser.Scene().CurrentActor().Parameter("xTran").SetUpdateCallback(cheapskatesXTranCallback)

print "Setting up the 'zTran' callback..."

poser.Scene().CurrentActor().Parameter("zTran").SetUpdateCallback(cheapskatesZTranCallback)

print "...done."






The 3Dcheapskate* occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.

*also available in ShareCG, DAZ, and HiveWire3D flavours (the DeviantArt and CGBytes flavour have been discontinued).