I’ve got a python script linked to a blender object. Is there a way to determine how far the object has moved from one frame to the next.
At the moment I’m measuring the distance from a fixed datum, but that only works as long as the object is moving in a straight line away from the datum.
I suppose I could place an empty aligned with the object, then move to the next frame and measure the distance back to the empty. I just need to make sure that the empty is positioned on the object for frame 1, using on onLoad script perhaps.
Any variable defined outside of a function/class is global, no need to use any keywords, HOWEVER, this is not true anymore for Blender versions >223, so it will not work for Publisher. Variables only exist for as long as the script is running. For 223 and lower, try this:
a =123
print a
run it, then put a comment in front of a=123, and run again, the variable contents will still be printed.
Thanks for your help, I’ve now got a solution that will work most of the time in 223.
Basically, I test the frame number and ignore the operation (print in this case) if this is the first of the animation. This prevents the undefined variable from being referenced and causing an error.
if (Blender.bylink) :
mObject = Blender.link
if (Blender.Get("curframe") != 1) :
print mObject.LocX, oldx
oldx = mObject.LocX
As long as I save the animation on frame 1, I should not get any problems.