PDA

View Full Version : Import CSV-List and fill UserData-Fields


jskw
02-07-2013, 11:41 AM
I am looking for a way to import a csv-file (with undefined number of rows) and set userdata of an Object with the values from the file.
The Userdata have to Change in dependency of a frame.

Is this possible?

Here a example of the csv-file:

Each "column" of csv-File contains a value of userdata:

C1, C2, C3, C4, C5
1, Name1, 100, 200, 50
2, Name2, 75, 100, 75
.
.
.
88, Testname , 180, 300, 200

Result:


Frame 1:
Userdata1: Name1
Userdata2: 100
Userdata3: 200
Userdata4: 50

Frame 2:
Userdata1: Name2
Userdata2: 75
Userdata3: 100
Userdata4: 75


Thank You!

NiklasR
02-07-2013, 06:02 PM
Hi jskw,

You can use the csv (http://docs.python.org/2/library/csv.html) module to read in the file. You can set the userdata-field with ID 1
like op[c4d.ID_USERDATA, 1] = value.

-N

jskw
02-07-2013, 08:52 PM
Hello Niklas,

thank you for your reply.

Is it possible to select a specific value from the csv-table?
for example:

row 2, column 3 = value5
Thank you

littledevil
02-08-2013, 02:19 AM
a csv reader is just a 2d array, or in pythonish, is an iterator:

data = csv.reader(my_csv_string)

for row in data:
for cell in row:
print cell

so it would be value = data[row][cell].

NiklasR
02-08-2013, 03:33 PM
>>> a csv reader is just a 2d array, or in pythonish, is an iterator:

Not exactly. It is an iterator, but not a 2d array. You have to convert it before subcsripting,
eg. using a list-comprehension:

reader = csv.reader(open("foofile.csv"))
data = [row for row in reader]
print data[2][3]

-Niklas

jskw
02-09-2013, 07:41 PM
Here is a solution of my problem in a german forum!

Thank you Niklas!

Here is the Link:

http://www.tutorials.de/cinema-4d/392309-csv-datei-importieren-und-benutzerdaten-felder-mit-werten-aus-csv-fuellen.html

CGTalk Moderation
02-09-2013, 07:41 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.