Change Object Color While Animation based on Text File

I assume that Sphere is your Object whose
color has to be changed according to the
text file red.txt, green.txt and blue.txt.
There file red.txt, green.txt and blue.txt
has 250 lines i.e. 25 line per second.
At each frame the color will be changed
according to the value supplied by the
text file.

1.Copy these 3 files in c: mp directory
2. Open your Blender File
3. Create A Cube
4. Goto Frame 1 and in the 3D Window Press I
while you still selecting Cube
5. It will ask for Type of IPO, You opt for Loc
6. Main Window->Animation
7. Side Window Select Text Window and Type the below noted Python script
import Blender
from Blender import *
import sys
mf=open(“c:/tmp/red.txt”,“r”)
myIpo=Object.Get(“Cube”).getIpo().getCurve(“LocX”)
myIpo.setInterpolation(‘Bezier’)
for frame in range(1,251):
mline=mf.readline()
myIpo.addBezier((frame,float(mline)))
myIpo.update()
mf.close()

mf=open(“c:/tmp/green.txt”,“r”)
myIpo=Object.Get(“Cube”).getIpo().getCurve(“LocY”)
myIpo.setInterpolation(‘Bezier’)
for frame in range(1,251):
mline=mf.readline()
myIpo.addBezier((frame,float(mline)))
myIpo.update()
mf.close()
mf=open(“c:/tmp/blue.txt”,“r”)
myIpo=Object.Get(“Cube”).getIpo().getCurve(“LocZ”)
myIpo.setInterpolation(‘Bezier’)
for frame in range(1,251):
mline=mf.readline()
myIpo.addBezier((frame,float(mline)))
myIpo.update()
mf.close()
When you execute this script you will see that Cube Ipo LocX,LocY and LocZ are updated
in 250 frames.
Now Select Your Sphere and give the New Material for example you given Red color and the
name of the material is RedMat. Goto IPO Window, Select Material, Click on R channel and Goto Frame No. 1
Press Control Key and with Mouse Click on 0 value.
Now Select New Cube. Select Ipo Window (Object) Click on LocX channel and Copy the elected Curve
into the Buffer by Clickin on the UP Arrow.
Now Select your Sphere, Ipo Window (Material ), Select Red Channel, and Paste the Curve from Buffer.
In the same manner, copy the Cube->LocY Curve to Sphere->Material-IPO->G and Cube->LocZ Curve to Sphere->Material-IPO->Blue channel.
Now when you run your animation you will see how the color is changing frame by frame.