Script request

Does anybody know of any script able to save the infomation af the IPO curves of a selected object in a txt file? I´m trying to use the game engine for some rough simulations but i need to import the IPO data into excel and i dont find any exporter… :expressionless: :expressionless:


This isn’t a full version - it’s a toy for writing scripts
cutting and pasting the output to another window

It saves the curves to a txt window in blender
as a dictionary… it only exports the coordinates
but not the handles of a bezier triple.

It’s not hard to modify to export more data

It exports other data types too if you use the
other wrappers for materials and particles

import Blender
import sys

from Blender import Object,Material

def getFreshText(name):
  x = Blender.Text.Get(name)
  x = Blender.Text.New(name)
 return x

def prettyPrint(dict):
 show = []
 for key,value in dict.items():
  show.append("%s = %s" %(key,value) )
 return "%s

class ObProps:
 def __init__(self,obj):

  props ={}
  getters = [x for x in dir(obj) if x[:3] == 'get']
  for method in getters:
    exec 's = obj.%s()'%method
    props[method[3:]] =  s
    print "props warning : skipping %s"%method = props

 def __repr__(self):
  tmp = [ (repr(a).ljust(15),repr(b).ljust(25)) for a,b in]
  return ''.join(["%s%s
"%x for x in tmp])

 def asSetters(self):
  show = []
  for key,value in
   show.append("obj.set%s(%s)" %(key,value) )
  return "%s

 def asDict(self):
  show = ["{"]
  for key,value in
\'%s\' : %s" %(key,value) )
  if len(show)==1:
   show[-1] = "

  return "".join(show)

def exportIpo(name):
 ipo = Blender.Ipo.Get(name)
 exportDict ={}
 exportDict['Name'] = name

 cvs = {}
 for posCv,cv in enumerate(ipo.getCurves()):
  #dd['Extrapolation'] = cv.getExtrapolation()
  pts = []
  for x in cv.getPoints():
	y = x.getPoints()
  cvs[cv.getName()] = pts
 exportDict['Curves'] = cvs
 return exportDict

def printIpo(dict):
 xx = ["%sIpo = {"%dict['Name'],]
 for name,pts in dict["Curves"].items():
  xx.append('''"%s" :  '''%name)
  ptStr = ["["]
  for a,b in pts:
  ptStr[-1] = "]"
 xx[-1] = "
 return "".join(xx)

def matData(name):
 mat= Blender.Material.Get(name)
 fp = getFreshText(''%name)

def ipoData(name):
 fp = getFreshText(''%name)

def partsData(name):
 parts = Blender.Effect.Get(name)[0]
 fp = getFreshText(''%name)

ipoData("trail") #export the ipo called "trail"

Ooow! Thx for the early reply! I cannot get it working for now (sintax error in line 70) but i´ll try later at home. thx again! :slight_smile:


I checked this it appears to be a stupid indentation error
at that line.

Otherwise it appears to do what I said
I guess if you want to import to excel
you should really write a csv file

so you want to loop over the dictionnary that
exportIpo returns writing a line per curve
or something like that.

It’s not difficult to mod to do this.

If you have a problem then I can
fix it to do this tomorrow…

Yes, actually what I need is 4 columms: frame,x,y and z values for the selected object. One csv file could be enough to import the data to excel…
I´ve seen there is an import script for csv but it cannot be used to export (i think)

I think this is what you want.
It actually writes 4 rows but I guess that shouldn’t matter?

You set the sfra startframe and efra endframe
and the name of the output file…

import Blender 
import sys

sfra,efra = 1,20
obj = Blender.Object.GetSelected()[0]
ipos = obj.getIpo()
times = [1.0*t for t in range(sfra,efra)]
dict = {"time": ["%.2f"%t for t in times]}
for cvn in "LocY","LocZ","LocX":
		cv = ipos.getCurve(cvn)
		dict[cvn ] = ["%.3f"%cv.evaluate(t) for t in times]
		dict[cvn ] =["Nan"]*len(times)

outFile = "c:/ipo.csv"
fp = file(outFile,"w")
for cvn,data in dict.items():
	fp.write(cvn + ";")

Why not support bvh rather then write your own animation format?

It works now perfectly, exactly what I wanted. THX! THX! :smiley: