On run stop export dashboard to csv file

On run stop export dashboard to csv file

farahabdoune
Observer Observer
132 Views
3 Replies
Message 1 of 4

On run stop export dashboard to csv file

farahabdoune
Observer
Observer

Hi everyone,

I’m trying to automatically export a given dashboard (e.g., Output by Hour) as a CSV file On Run Stop
So far, I’ve only found the option to export a table manually via the Excel Import/Export feature, but that still requires me to do it by hand.

Does anyone know how to achieve this using FlexScript?

Thanks in advance!

0 Likes
133 Views
3 Replies
Replies (3)
Message 2 of 4

moehlmann_fe
Advocate
Advocate

You can use the "exporttable()" command for this if you first install the components of the chart to get access to the Statistics Collector.
exporttable(Table("Output By Hour Collector"), ...)
Note: "On Run Stop" triggers everytime the model stops, including manual stops by clicking the Stop button. Maybe it would be better to create a user that triggers just ahead of the planned model end time.

https://docs.flexsim.com/en/25.2/Reference/CodingInFlexSim/CommandReference/Commands.html#exporttabl...

 

The answer by Logan Gold on the following post exposes the needed code to emulate the "Export to CSV" function in the right-click menu of a dashbaord.

https://forums.autodesk.com/t5/flexsim-forum/export-all-dashboards-to-csv-using-flexscript/td-p/1358...

0 Likes
Message 3 of 4

farahabdoune
Observer
Observer

Thanks for your answer, for now im using this code : 


treenode collector = Model.find("Tools/StatisticsCollectors/Output By Hour Collector");
string fileName = "Output_By_Hour_Collector.csv";
Table.query("SELECT * FROM [" + collector.name + "]").cloneTo(Table("GlobalTable3"));
exporttable(Table("GlobalTable3"), fileName);

The problem is the imported values are not correct, as you can see below, any idea how to fix thjs please ? 

thanks ! 

farahabdoune_0-1756213989373.png

 

0 Likes
Message 4 of 4

moehlmann_fe
Advocate
Advocate

The values are 'correct', just not in a human readable format, because the exporttable() command exports the raw values. Since you clone them to a global table before exporting you could just convert them.

Table clone = Table("GlobalTable3");
for(int row = 1; row <= clone.numRows; row++)
{
	DateTime dt = DateTime(clone[row][1]);
	clone[row][1] = dt.toString();
	
	string objectName = Model.find(StatisticsCollector.getPathFromID(clone[row][2])).as(Object).name;
	clone[row][2] = objectName;
}
0 Likes