# Mograph - How would I create a multi dimensional bar / area graph using CSV & Matrix Object

#1

Hi All,

Im having difficulty getting my head around this one. I’m trying to create a multi dimensional bar / area graph that is using a Matrix Object to define points from CSV and each needs to have their own value of height from CSV file?

I’m currently using an Object to define points in the structure but how do I set the heights as i’m using the structure to define where all the locations of the bar graphs.

Do I need to go to python scripting or is there a way to link more than 3 columns of userdata?

Do I need to jump into python or can I get around with importing ascii data?

The full thing I need to do is have a the bargraphs animation with a full matrix per keyframe but I can start by just solving viewing one keyframe of the bar graph

Let me know if you can help on this one, much appreciated.

Cheers!

#2

I just recommend learning Python. Python makes everything so easy. I loaded in a set of y coordinates from a .pickle file like this and used them to set the points of a spline:

``````import c4d
import random
import pickle
import os
import json
#Welcome to the world of Python

def main():
print(os.getcwd())
numpoints = int(1680/15)
repeat = 2
total_points = repeat*numpoints - 1
spline = c4d.SplineObject(total_points, c4d.SPLINETYPE_LINEAR)
if spline is None:
return None

spline.ResizeObject(total_points, 1)

# Offset & Set the Points
spline.SetSegment(0, total_points, False)

with open('yy_points.pickle', 'rb') as handle:
pntnum = 0
for ii, yc in enumerate(reversed(yy)):
spline.SetPoint(pntnum, c4d.Vector(10*pntnum, 621.6*yc, 0))
pntnum += 1

spline.Message(c4d.MSG_UPDATE)

return spline
``````

Where I loaded the pickle file from a list of points that I dumped in a separate python program I ran from my OS’s installation of Python:

``````yy = [1,4,8,4,2,5]
with open('yy_points.pickle', 'wb') as handle:
pickle.dump(yy, handle, protocol=2)``````

#3

When does `spline` become `None` ?

#4

Sorry, I think that may have just been temporary code I left in there while testing. It’s unnecessary and can be removed. The main thing is just to look at how the data points are being read in and how the spline’s points are set. It would just need to be adjusted to read in a csv file instead (can be done with the pandas package). Then you could iterate over the rows to get the point coordinates.

#5

Actually it can at any time. There’s a fresh spline created in the script and this can fail, for example due to insufficient memory. Thus this None test is not some kind of temporary code, but it should be there in clean code. Error checks in code are not something nice to have, but should be viewed as mandatory everywhere. And actually the ResizeObject() would need a check as well.