A Script to Import a CSV File and Create F-Curves (for Blender 2.5x or later)

Hans, Thanks again for the script. It was the crucial tool that enabled me to create a procedure for importing skeleton and motion capture data from a Vicon IQ system into Blender 2.6. I’ve posted the complete procedure here in case someone else is facing a similar challenge.

@bbattey

Thank you so much for using my script and including it to your blog!!! I’m really pleased. Great work!

I had to comment out the following in the v0_7_alpha1code to get it to run in Blender 2.63. That may not be necessary now:

  • import unittest
  • the def main()… block
  • the class Test_FCurvePointAdder… block

Sorry for the inconvenience you had to change parts of the code. I’m not sure why Blender has become not to include module unittest…

Hi,

I am using this add-on quite often. And due to the help bbattey it was possible to use this add-on in the last releases of Blender.
So thank you very much bbattey.

Now for the new release 2.66 this add-on is unfortunately not working any more. It appears in the AddOn Section under User-Preferences, but it is not possible to activate the check bock.

Does anyone has an idea who this script can activated in 2.66??

Greetings
dechgo

I am having the same issue. I can revert to an older version I suppose, but I am curious about why it doesn’t work.

Thanks!

Hello Hans.P.G,

I have csv output from a simulation with 300 agents for 500 time steps. An example of the output:

time,ID,rotation,x,y
0,0,97,-30.9718651376,-12.5577285025
0,1,330,-4.0068009368,2.4359169362
0,2,41,15.8423968721,33.3134918227
0,3,338,-7.8448049789,-1.9588494272
0,4,235,15.7923798083,-19.5570376247

Can your script handle multiple agents imported at the same time, or would I have to break the output per agent?

Many thanks!

@@Dechgo

Sorry for being late. I found a workaround by just removing the feature to select data path name from the suggestion list. I cannot find out how to make it work correctly so far.

I’ve updated v0.7 alpha3 on https://sourceforge.net/projects/csv-fc-importer/, which was confirmed to work on Blender 2.67.

@@Sorbus

In your example, it has one “time” column and four data columns of ID,rotation,x,y. But in your actual case, there are 300 data columns, am I correct?

The script can import several data columns at the same time, but you have to make setups for each column, which means that you have to make setups 300 times for 300 data columns. In that case, you may create another small script to avoid the 300-times setups by hand…

Hi Hans.P.G.,

Many thanks for your reply. The example shows all of the columns. ‘time’ for the simulation ticks, ‘ID’ for the unique agent identity, rotation, x and y. A simplified example with three agents would be:

time,ID,rotation,x,y
0,1,...,...,...
0,2,...,...,...
0,3,...,...,...
1,1,...,...,...
1,2,...,...,...
1,3,...,...,...
2,1,...,...,...
2,2,...,...,...
2,3,...,...,...

I’ve attached a zippped .csv of a flocking simulation for you to see. I wonder if this is a typical data structure for the type of program?

Many thanks,

Sorbus

flocking.csv.zip (2.98 MB)

@@Sorbus

I see. ID means the object number.
In this case, the script cannot handle such a .csv file, but one of the workarounds is to transform the .csv file to another .csv form that contains:

time, rot_ID1, x_ID1, y_ID1, rot_ID2, x_ID2, y_ID2, rot_ID3, x_ID3, y_ID3, …

300 x 3 + 1 = 901 columns will be created, and then the script will import with the settings of:

Object name: ID1
time column: 0
rotation_euler[0]: 1
location[0] column: 2
location[1] column: 3

Object name: ID2
time column: 0
rotation_euler[0]: 4
location[0] column: 5
location[1] column: 6

Oh, I realized that the script can import data only to a single Object which is selected in 3D View currently. Importing data to different Objects needs to repeat importing by hand.

For importing such large data, it will be better to create a specific script. You provided the data, so I can help.

That’s great news, thank you very much. I imagined something like being able to import the CSV first and have it create empties or apply to duplicates of an object of choice.

Hello Hans.P.G.,

Did you have any success with the CSV file?

Best wishes,

Sorbus

@Hans.P.G.: great add-on :slight_smile: any chance to get updated version for 2.74 / 75?
Thank you for info.


Edit: I could not activate add-on in 2.57 version either (under OS X 10.8.5)

Thank you for your information.
I didn’t know the script doesn’t work on Blender 2.74.

Looking at the picture that you provided,
it looks like the Blender interface of Python has changed,
and the module bpy.data no longer has the property scenes.

I put all the necessary data into that bpy.data.scenes[0] in the script.
I have to find out another place to put it in the new version of Blender.
I will search on the web to find how to do so in general.
I guess it will take time.

It’s quite helpful if anyone has some information for that.

Just from your point of view … does it “takes time” in hours, days or weeks … I don’t want to push you, just manage my time :slight_smile: Your useful script is just a beginning for me :slight_smile: Thank you very much.

(I didn’t want to make someone hurry, so I tried to work with 2.57 version, but in blenders repository are version 36147 and 36339 revision for 2.57b, and script is done for 35853 :slight_smile: In that time api changes were very often, seems like that is why I felt to run your script in 2.57 versions too.)

It will take weeks. I’ll have time soon in May.

There’s also this:

http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html

Blender now includes the numpy library, so if you are doing anything to a list of numbers, you should look into it.

@Hans.P.G: Thank you for info.

Edit: Dropping script directly into blender’s Text Editor window and running script from there – works !!! :slight_smile:

@Bayesian: It’s nice advice. I’m also Numpy user so I feel comfortable with it.
@vklidu: Thank you. That’s helpful information when I figure out why my script fail in the Addon setting window.

I think it has to do with the accessing the bpy.data inside the register function maybe some kind of security feature , so by moving the data access from the register to the end of the script will get it to register correctly, the following part is what needs to be changed :

#---=== Register ===

def register():
    
    bpy.utils.register_module(__name__)
    bpy.types.Scene.CONFIG_CsvFcurveImporter = bpy.props.PointerProperty(type=ImporterUIConfig)
    
    # sec: set up data_path_candidates
    #moved outside Register()
    

def unregister():
    
    bpy.utils.unregister_module(__name__)

    if bpy.context.scene.get('CONFIG_CsvFcurveImporter') != None:
        del bpy.context.scene['CONFIG_CsvFcurveImporter']
    try:
        del bpy.types.Scene.CONFIG_CsvFcurveImporter
    except:
        pass

if __name__ == '__main__':
    register()

   # sec: set up data_path_candidates
    config_top = bpy.data.scenes[0].CONFIG_CsvFcurveImporter
    
    for index in range(len(config_top.data_path_candidates)): # clear data path menu items first
        config_top.data_path_candidates.remove(0)
    for name in ["location", "rotation_euler", "rotation_quaternion", # create data path menu items
                 "rotation_axis_angle", "scale", "dimensions"]:
        config_top.data_path_candidates.add().name = name

the Addon .py file

Thank you for fix :slight_smile: It works for me.