A Script to Import a CSV File and Create IPO Curves/Meshes (for Blender 2.4x)

(If you use Blender 2.5x or later, please use new CSV F-Curve Importer and CSV Mesh Importer instead.)

What is CSV Importer first:
This is a Python script to import a CSV file into Blender and create IPO curves or meshes.

Name:
CSV Importer v0.5 beta3

Download:
CSV_Importer_v0_5beta3_ps.zip

Main features:
This script, CSV Importer can import data of a text file formatted with CSV into Blender and create IPO curves or meshes. When CSV Importer is useful is following. When you do a physics simulation using motion equations, what do you do to see the result in which many objects move in a 3-dimensional complicated way, for example? A way for it is to use Blender and animate the motions and make a video. So CSV Importer will help you to import the result of the simulation to animate them. And all that you have to do is to save the result as a CSV file in advance and create IPO curves from the file with CSV Importer.
http://bp3.blogger.com/_d4nbesSwQqc/Rso9cExHKFI/AAAAAAAAAEE/lXD9XkK3FLY/s400/CSVImporter_Overview.jpg

Start to Use Easily: (Video)
+1. Download a file “CSV_Importer_v0_5beta3_ps.zip” at here. Then unzip it and make sure a file “CSV_Importer_v0_5beta3.py” is created.
+2. Close Blender if running.
+3. Put the file “CSV_Importer_v0_5beta3.py” to “%BlenderInstalledAddress%/Blender/.blender/scripts”. (%BlenderInstalledAddress% means the address in which Blender is installed.)
+4. Have a CSV file. For example, put some time data in the first row and some x-coordinate data in the second row. (You can use a sample CSV file which is included in the zip file and named as “1_Data_MostEasily.csv”.)
+5. Start Blender.
+6. Select an Object. You will animate this Object by importing the CSV file.
+7. Change Window Type from 3D View to Scripts Window.
+8. Select “Scripts >> Animation >> CSV Importer v0.5 beta3 (.csv)” from the menu. CSV Importer will start.
+9. You will see a dialog window to select a file. Select the CSV file which you prepared at the +4. step and click the button, “Import (.csv)”.
+10. You will see a window of setup to import. There are some select boxes under the label “To what key do you want to import the columns:”. These boxes mean each row in the CSV file. The labels, “1:”, “2:” of the boxes are the first, second rows in the file. Select [Frame] from the first box labeled “1:” because you put the time data in the first row of the file at the step +4. In the same way, select [LocX] from the second box labeled “2:” because you put the x-coordinate data in the second row. In this way, you can set up what row you import to what kind of IPO curves.
+11. Click the button, “Import”.
+12. These steps will get CSV Importer to import the file and you will get an IPO curve. (You can see a .blend file which includes the IPO curve created by these steps and the file is included in the zip file and named as “1_Result_MostEasily.blend”.)
http://bp0.blogger.com/_d4nbesSwQqc/Rso9cUxHKGI/AAAAAAAAAEM/0Oe7hpx6H68/s400/CSVImporter_Steps.jpg

A video on how to do the steps described above:
+How to Use CSV Importer v0.5 Most Easily
+The same video in Google Video

More videos on how to use the script:
+How to Import a Mesh with CSV Importer v0.5
+How to Import an Ipo Curve Automatically in AutoMode with CSV Importer v0.5
+How to Import a Mesh Automatically in AutoMode with CSV Importer v0.5

Requirements:
CSV Importer works on Blender. I confirmed it worked well on Blender v2.42-2.49b. In addition, if you use Blender v2.44, then you need to install Python 2.5 as well.
This script is only for Blender 2.4x. You can get another script for Blender 2.5x from this link.

Recent change logs:
v0.5 beta3 (2010/06/07)
+fixed the bug in which it doesn’t import a .csv file with detailed timeline. (Thank you for reporting, okchoir)
Go to here to see all change logs.

Information on CSV Importer:
Here is the page where you can find the reason why I made the script, the list of change logs, the future works and more.

Your comments and criticism is appreciated. :slight_smile:

Hello Hans

Brilliant work with your csv importer.

Could you tell me if it would work on my application please.

I have a series of x,y,z co-ordinates in a plain comma delimited csv file.Each line of the data set represents a point in 3 dimensional space.

I want to import these into blender, join up the points to make a mesh surface, then render the surface and export it to a dxf file. (The dxf export works fine.)

What I am trying to create is a Digital Terrain Model (DTM) from a series of surveyed x,y,z points. (Easting, northing and reduced level in ground surveying terminology).

I have a dataset of around 200 points but would like to have as many as 2,500 points in my DTM.

Kind Regards
Bob

Errr … pardon me, Sir, but is there any other way to download your script without having to “register to esnips”?

I’d really like to take look at it.

You don’t have to register?
Just look at the archive icon on the left when you open the linked webpage.

Thank you for trying to use this script and I understood what you want to do, bwallum. I don’t know what the series of x,y,z points is like, but if the data is like a square grid, then I guess there will be a way available. The following is a way which will make it possible to import a map mesh using this script.

+1. Assume that the data you want to import is like the following, for example:
x1,y1,z1 ,x2,y2,z2 ,x3,y3,z3 ,x4,y4,z4 ,x5,y5,z5
0,0,0.0 ,1,0,0.0 ,2,0,0.1 ,3,0,0.1 ,4,0,0.2
0,1,0.0 ,1,1,0.0 ,2,1,0.1 ,3,1,0.1 ,4,1,0.2
0,2,0.1 ,1,2,0.1 ,2,2,0.1 ,3,2,0.2 ,4,2,0.2
0,3,0.1 ,1,3,0.1 ,2,3,0.2 ,3,3,0.2 ,4,3,0.2
0,4,0.1 ,1,4,0.2 ,2,4,0.2 ,3,4,0.2 ,4,4,0.2
It is a grid over x:0-4 and y:0-4. The values of x and y define the position of a map and z define the height at the position.
+2. To automate the importing, make a .csv file in which setups are prepended like the following.
http://bp2.blogger.com/_d4nbesSwQqc/RvVl9WPS5gI/AAAAAAAAAE8/RKg1d_LDwCQ/s400/CSVImporter_MapMesh_csv.jpg
The real data of the file is:
Map1,
LocX,LocY,LocZ,
,New=Object,
Map1,
,LocX,LocY,LocZ,

Map1,
,LocX,LocY,LocZ,

Map1,
,LocX,LocY,LocZ,

Map1,
,LocX,LocY,LocZ

0,0,0.0 ,1,0,0.0 ,2,0,0.1 ,3,0,0.1 ,4,0,0.2
0,1,0.0 ,1,1,0.0 ,2,1,0.1 ,3,1,0.1 ,4,1,0.2
0,2,0.1 ,1,2,0.1 ,2,2,0.1 ,3,2,0.2 ,4,2,0.2
0,3,0.1 ,1,3,0.1 ,2,3,0.2 ,3,3,0.2 ,4,3,0.2
0,4,0.1 ,1,4,0.2 ,2,4,0.2 ,3,4,0.2 ,4,4,0.2
You can download the file at here.
+3. Import this .csv file using the script. Select AutoMode at “CSV file format is:” and click Import button.
+4. You’ll see 5 lines created and get 5 Objects including a line-shaped mesh each. Select them all and press [Ctrl+J] to join them to an Object.
http://bp0.blogger.com/_d4nbesSwQqc/RvVsQ2PS5iI/AAAAAAAAAFM/uaHsWkVGGC0/s400/CSVImporter_MapMesh_0.jpg
+5. Press [Tab] and enter Edit Mode. Press [F], select Skin Faces/Edge-Loops in the menu, and select segment in the next menu. Then edges and faces are made appropriately and you’ll get a map mesh.
http://bp2.blogger.com/_d4nbesSwQqc/RvVl9WPS5fI/AAAAAAAAAE0/GAHvjwjdxzE/s400/CSVImporter_MapMesh_1.jpg
+6. This is the way that I can provide you to make a bump mesh using the script. Here is a .blend file that I made with these steps.

Also I think it is too big a hassle to write the setups prepended in the .csv file. I’ll keep on working for the update to enable you to import it more easily without writing any setups by adding another mode into “CSV file format is:” menu in the script, if you would like it and could wait for it leisurely.

Thanks for your attention to this script, tedi. As Syziph said, try to click the icon on the left of the esnips’ page where you jump from the link I provided. The page is like the following.
http://bp2.blogger.com/_d4nbesSwQqc/RvVqLWPS5hI/AAAAAAAAAFE/BsYAnMo-Lpg/s400/WS000000.jpg

Thanks for clarifying that. But that is an obvious and logical step upon confronting a clear layout such as that of the esnips.

However, in Opera, the page that opens after I click the link, invites me to login or register. Imagine that!

I solved the mystery with using the Internet Explorer, if that matters. The zip file downloaded promptly and without asking me to join.

Thank you for the explanation anyway.

@ Hans:
Sorry for the useless post but i have to compliment people like yourself !
Although i probably wont use your importer (at least in a near future), i would like to show my respect to people like you for actually sitting down and producing stuff that broadens the possibilities of Blender…
I hope to be able to do just that some day… (learning python…hmmm)
Well done !

One use of converting csv to mesh could be generation of 3D charts for presentations or data visualisation :slight_smile:
I was looking for such type of interpreter, so this script is a “must have” for me.
My complements, Hans!

Oh no… I’m really sorry, tedi. I really didn’t know that such a troublesome matter happened. I have confirmed whether the downloading would work or not in esnips pages with only IE and Firefox. That’s obviously my lack of effort of checking up the availability for download, sorry. And I thought I had to tell esnips developers this big problem so I tried clicking the link to the esnips page with Opera, which I newly installed, but I couldn’t see the inviting login page and it worked well in Opera as well as in IE so far. I used the newest version of Opera on Windows XP as the following image indicates. Could you tell me what the difference that causes the different results between yours and mine will be, if any, please.
http://bp1.blogger.com/_d4nbesSwQqc/RvXuQGPS5jI/AAAAAAAAAFU/mDX8WkGFrF0/s400/Esnips_Opera.jpg

Gwenouille, thanks. Your post is encouraging me. I’ll keep on working for a more powerful importer. It would be happy if you remember that until you have to import a .csv file and keep your eyes on my development of the script.

Syziph, thanks. I’m glad you liked it. I used the script to make a video to show how a compass-shaped robot walks and you can see it at here. I took a numerical simulation based on mathematically derived motion equations with another software and saved the result as a .csv file then imported it with the script and made Ipo curves to animate the legs of the robot or something. When you complete your works of 3D charts or anything, it would be nice if you let me see them.

Hi Hans,
your script is exactly what I was looking for, thanks a lot.
I have a small request: would it be possible to import a sample of data from the csv ?
I mean, I have files with about 50k time steps and it takes forever to import, moreover I don t need all time step to represent the motion of an object.
So if it was possible to have the choice to import say n time steps evenly sampled among the 50k time steps, that would be great and make life a lot easier.

Thanks again :slight_smile:

Legu.

Billant work Hans !!

since i didn’t tested yet, i plan to.
i have a sugestion, could it use a serveral difent data separators rater than comma “,”
i have a lot of data separated by semicolon, space, tab, and so on
since a spread sheet can only handle 65k lines, my files come over 170K so put
commas to tese files wold be a headache.

thank you, people like you make a better wolrd !

Thanks for your replying which got this thread active again.

@legu: I understood what you said. I didn’t consider such a way of importing so plenty amount of lines when I wrote the script. Though I haven’t explained all of the ability the script has in English yet, you can already specify the range of data including lots of lines, but it’s possible only in AutoMode so far, so you have to write something to setup the range in your csv file. Here is how to do for the range settings.
+1. For example, I assume that you have a small csv file like the following. I’m going to edit it in Excel 2003.
http://bp1.blogger.com/_d4nbesSwQqc/RyBWhwus6eI/AAAAAAAAAHE/Fq7ZxXJty_w/s400/ForRange1_20071025.jpg
+2. Add 3 rows to the head of the file. Then write the settings as follows. The key point is to write the setup values like “From=2;To=4;” for the range specification in A,3 cell. It will lead a result in which the script imports the only 2-4 rows data as specified.
http://bp2.blogger.com/_d4nbesSwQqc/RyBWiAus6fI/AAAAAAAAAHM/b61Pscz7rUw/s400/ForRange2_20071025.jpg
+3. Now save the data as a csv file, and in the script, open it, select AutoMode, click Import button and import the file. Here is the result screenshot of Blender.
http://bp2.blogger.com/_d4nbesSwQqc/RyBWiAus6gI/AAAAAAAAAHU/R2kJ4JegkWI/s400/ForRange3_20071025.jpg
If you have so large csv file that you can’t edit it in Excel as Willington says, please use a simple text editor and prepend the data which you can see by opening the csv file made in step +3 with the text editor. It is like this:
http://bp3.blogger.com/_d4nbesSwQqc/RyBWiQus6hI/AAAAAAAAAHc/leAHmQ6ByqA/s400/ForRange4_20071025.jpg
The .csv file and the .blend file are available for download.
I know this way is not simple to use, and I’m going to improve this hassle point so that you can specify the settings for the range or more in GUI.

@Willington: 170K lines, so large! Is it created via motion capture data? Anyway, your suggestion is surely one of the features that I have to add. I first knew it was neccesary to be able to select the data separators, thanks. I’ll do it in the next version.

I really want to help more people who need a tool to deal with a large data table or something. Your posting will spread the script widely and make me happy, thanks again.

Hi Hans,
thanks a lot for taking time to answer.
It seems I didn’t give clear enough explanations of my request, sorry about that.

Here is a small python script I made to do what I tried to explain, it samples evenly approximately NumberOfSamples values among all time steps :

lines = InputFile.readlines()

NumberOfTimeSteps = len(lines)-1

SamplingPeriod = NumberOfTimeSteps / NumberOfSamples

LineIndex = 0
for line in lines[1:]:
    if LineIndex%SamplingPeriod == 0: OutputFile.write(line)
    LineIndex += 1

The offset of 1 is for the file header and a user input for NumberOfSamples is required.
In the end OutputFile has about NumberOfSamples lines in it.
That would be great if you could add this feature to your script !

Thanks again.

@legu: Ohh… I had a misunderstanding, sorry. I really understood you this time from your explanation you so kindly provided. It might be more easy to do so with the script. There is no need to use AutoMode. You will find Drop setup in GUI which will sample data. If you set Drop value to 1 instead of 0, then 1, 3, 5, 7… rows of the data will be taken into Blender. Drop value to 2, then 1, 4, 7, 10… rows will be done. This value means how many rows you want to drop down to reduce the data with loss of precision, and I guess it will have the same meaning as SamplingPeriod value in your script.

http://bp2.blogger.com/_d4nbesSwQqc/RyE96wus6iI/AAAAAAAAAHk/TF2vvnpUkj4/s400/ForSample_20071026.jpg

Perfect !

ありがとう Hans.

(hope the translation is ok ^_^)

ha ha, I was surprised that some characters in Japanese can be seen in this forum. No sweat, and sorry for my bad English.

You have done an excellent work! I was exactly looking for such an application you created.
I have about 500,000 (sometimes 1.5 million) 3D points, which has been produced by field surveying using 3D laser scanner with 2mm resolution. They represent x,y,z earth coordinate in the following form in text format ( I have omitted the first 5 digits of x,y coordinate):

X Y Z
22.534 29.878 12.118
22.535 29.882 12.128
22.535 29.880 12.129
22.533 29.878 12.121
22.533 29.878 12.121
22.533 29.877 12.121
… … …

I can separate the columns also by comma.
What I need to do is creating a 3D mesh out of these points, which represents a vertical face of a riverbank with some negative slopes, and then calculate the erosion volume of the river bank by subtracting two successive measurements (here 3D meshes).
I would like to know if it is possible through your CVS program to create such a 3D meshes.

Thank you in advance

Thank you for finding out my script and thinking of it.
The script itself has no ability to create a 3D mesh so far. But if the point data is sorted appropriately, then it can create a 3D mesh as you can see in the #5 post. Actually the script can only create a 2D mesh like a polyline, so you need to do something to create a 3D mesh in addition to importing a CSV file with the script.
I’m sorry if I have a misunderstanding, but I can’t have imagined how the 3D points should translate into a 3D mesh. But now I understood that there is a lot of need to convert a sequence of points to a 3D mesh, since you and bwallum gave me the similar replies. So I want to implement such a functionality to the script to make it more comfortable for everyone who use Blender and CSV files. In order to know more detailed information on what you want to do, could I get a sample of your CSV files that you are going to deal with?