For a pilot study I was looking for a simple way to output the Euler coordinates of an object as CSV from Cinema4D.

The problem was complicated by the fact that the object was animated by keyframes. Therefore the CSV should create a new line for each frame and store the respective X, Y and Z coordinates in this line.

After I was not quite satisfied with the solutions in the web (among other issues, there was no possibility to choose the delimiter within the CSV), I decided to tackle the problem on my own.

The solution presented below consists of two components.

- an Xpresso blueprint, which stores the coordinates internally, converts them from vector to real representation and passes them on to a short Python script.
- a quick-and-dirty Python script, which finally writes the final CSV as *.txt on the disk.

## Xpresso Blueprint

It looks a lot more complicated as it really is. Basically it catches the coordinates from Object A (box in the top left corner) and passes them to the Python-Script in the bottom right.

In order to get the respective frame the current time is also included (bottom in the middle – labeled with „Zeit“).

## Python Script

import c4d from os import path as p Writing Coordinates for each frame to txt file def main(): global Output1 global Output2 Output1 = Input1 # x Output2 = Input2 # y Output3 = Input3 # z Output4 = Input4 # frame`txtstr1 = str(Output1) # x coordinates string conversion`

`print('x: ' + txtstr1)`

`txtstr2 = str(Output2) # y coordinate string conversion`

`print('y: ' + txtstr2)`

`txtstr3 = str(Output3) # z coordinate string conversion`

`print('z:' + txtstr3)`

`txtstr4 = str(Output4) # time string conversion`

`file = open('pytest.txt', 'a+') file.write('time: ' + txtstr4 + ' || coordinate-x: ' + txtstr1 + ' || coordinate-y: ' + txtstr2 + ' || coordinate-z: ' + txtstr3 + '\n')`

`file.close()`

The script is a little questy, but it does what needs to be done. If a txt file does not exist it is created on the fly. The double pipe („||“) is used as delimiter but can be adjusted to your personal needs.

## Output

I am quite happy with the results, since the setup creates files like this:

time: 1 || coordinate-x: -64.8826566081 || coordinate-y: -70.0010456124 || coordinate-z: -82 time: 2 || coordinate-x: -64.5302801849 || coordinate-y: -67.8849231196 || coordinate-z: -82 time: 3 || coordinate-x: -63.9517590449 || coordinate-y: -64.4184924674 || coordinate-z: -82 time: 4 || coordinate-x: -63.1536689749 || coordinate-y: -59.6519862543 || coordinate-z: -82 time: 5 || coordinate-x: -62.1421783213 || coordinate-y: -53.6362818703 || coordinate-z: -82 time: 6 || coordinate-x: -60.9231593477 || coordinate-y: -46.4228331589 || coordinate-z: -82 time: 7 || coordinate-x: -59.5023014813 || coordinate-y: -38.0636069251 || coordinate-z: -83 time: 8 || coordinate-x: -57.8850274255 || coordinate-y: -28.6098803973 || coordinate-z: -83 time: 9 || coordinate-x: -56.0773644864 || coordinate-y: -18.1166362554 || coordinate-z: -83 time: 10 || coordinate-x: -54.0849356908 || coordinate-y: -6.636005316 || coordinate-z: -83 time: 11 || coordinate-x: -51.9137727113 || coordinate-y: 5.77858217798 || coordinate-z: -82 time: 12 || coordinate-x: -49.570226436 || coordinate-y: 19.0734755266 || coordinate-z: -82 time: 13 || coordinate-x: -47.0610401283 || coordinate-y: 33.1948638769 || coordinate-z: -82

Needless to say: This project is highly work in progress. If you use any of my learnings (or my spaghetti-code) you do this on your own risk.

Die Kommentarfunktion ist deaktiviert.