## export graph to csv

Typically: "How do I... ", "How can I... " questions
tjk
Posts: 4
Joined: 28 Sep 2017, 17:06

### export graph to csv

Hello,

I will be running a large number of simulations. For each simulation I would like to export data from a graph object. I see that I can manually export to a csv via File -> Export -> Selected graphs as CSV. I anticipate this will not be efficient for a large number of simulations. I see that simGetGraphCurve is an API function with the following inputs: graphHandle, graphType, and curveIndex. I cannot find any supporting documentation for simGetGraphCurve. If this function is not supported is there another way to export graph data via a child script?

Thank you!

coppelia
Site Admin
Posts: 7543
Joined: 14 Dec 2012, 00:25

### Re: export graph to csv

Hello,

there are two ways of doing this programmatically:

1. You generate the data yourself in a script an keep track of it (e.g. in a table), then export the data by opening and writing a file with Lua.
2. You use simGetGraphCurve. That function is not documented because more meant as a backward compatibility feature. But here is how it works:

Code: Select all

string label,number curveType,table curveColor,table xData,table yData,table zData,table minMax=sim.getGraphCurve(number graphHandle,number graphType,number curveIndex)
graphType: 0=time, 1=x/y, 2=3D
curveIndex: zero-based index, that allows you to parse through the curves. If no curve is at the given index, nil is returned
curveType: 0=pts are linked, 1=pts are not linked
minMax: the min/max values for the curve

Cheers

atoz
Posts: 57
Joined: 18 Oct 2013, 09:02

### Re: export graph to csv

I was looking for a similar solution. Maybe in the future it would be nice to have access to the graph data via API so that the user can easily save the data they need since most of the work of collecting the data is already done to generate the graph.

Cheers

tjk
Posts: 4
Joined: 28 Sep 2017, 17:06

### Re: export graph to csv

Wonderful, thank you very much!