3
$\begingroup$

Salutations cronies, I am having trouble getting the Record Animation setting to work. I have read and watched a number of tutorials but I cannot get my animation to be recorded. Here:here is a link to get my blend file and below is the code for the module called by it (to get the characters ears to move in a continuous sinusoidal manner).

## Program to slowly alter vectors of bones and servos which is ####
## read by Blender ####
import os
import time
import math

i=0

def boneInstruc():

    while 1:  
        global i #necessary to ensure using global variable 
        xRE=round(math.sin(i),2)
        yRE=0.00
        zRE=0.00
        RE=[xRE,yRE,zRE]
        xLE=round(math.sin(i),2)
        yLE=0.00
        zLE=0.00
        LE=[xLE,yLE,zLE]
        xTL=round(math.sin(i),2)
        yTL=0.00
        zTL=0.00
        TL=[xTL,yTL,zTL]
        i=i+0.01
        #servo(xRE, xLE, xTL)
        time.sleep(0.01)
        return (RE, LE, TL)
$\endgroup$
  • $\begingroup$ you might want to use driver and expressions for this movement instead. Also does this code execute once per frame? $\endgroup$ – Vader Apr 2 '14 at 12:25
  • $\begingroup$ Thanks, I tried to use Bone Driven Shape Key animation in another file but it would not work either. All the internet examples seem to use the physics engines to do actions and to record them into the Time Line or DopeSheet (eg link). And yes the code executes once per frame. $\endgroup$ – CubeBot88 Apr 2 '14 at 12:46
1
$\begingroup$

Python scripts run blocking in Blender, which means Blender will wait and UI be locked until finished. You won't see an animation therefore, no matter if you use time.sleep() or not.

Use a frame change handler to register a callback function, that changes objects on every frame change (before or after):

http://www.blender.org/documentation/blender_python_api_2_70_release/bpy.app.handlers.html

| improve this answer | |
$\endgroup$
  • $\begingroup$ I may be wrong here but the link you sent me is for commands in the Python console - meaning then cannot be called in a Python BGE Module or Script. Could you be so kind as to show me how one calls the frame change handler in the BGE? -Alternatively, is it possible to extract data from a text file and use an Expression with a Bone Driven Shape Key animation to control the character (an alteration of Vaders comment)? $\endgroup$ – CubeBot88 Apr 24 '14 at 7:19
  • 2
    $\begingroup$ You should open two new questions for that, and add the game-engine tag! $\endgroup$ – CodeManX Apr 24 '14 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.