question

Sebastián Cañas avatar image
0 Likes"
Sebastián Cañas asked Sebastián Cañas commented

Export All Dashboards to CSV using FlexScript

Hi all,

I'd like to replicate the command Export All Dashboards to CSV using a button. How could I do it using FlexScript?

Thanks!

FlexSim 25.0.2
flexscriptcsvdata export
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Logan Gold avatar image
1 Like"
Logan Gold answered Sebastián Cañas commented

The code for "Export All Data to CSV" uses a function_s command:

treenode focus = node("..>viewfocus+", ownerobject(c));
function_s(focus, "exportData", 1);

You could do something similar, but you need an open/active Dashboard to do it, like this:

treenode AnActiveDashboard = views().find("active>Documents/Dashboard/1+");

if (AnActiveDashboard != NULL) {
    function_s(ownerobject(AnActiveDashboard), "exportData", 1);
}

But if you are putting this in a button on a Dashboard, that will guarantee there is an active Dashboard.

Also, since it is a function_s command, there is no guarantee it will work in future versions of the software.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Sebastián Cañas avatar image Sebastián Cañas commented ·
Thanks! @Logan Gold!
0 Likes 0 ·
zacharyh avatar image
1 Like"
zacharyh answered Sebastián Cañas commented

You can try creating a button in Dashboard and then adding the following custom code to the "OnPress" parameter for the button.

treenode link = node("..>objectfocus+", c);
/**Custom Code*/
Object current = ownerobject(c);

Array tableNames;
for (int i = 1; i <= Model.find("Tools/StatisticsCollectors").subnodes.length; i++){
tableNames.push(Model.find("Tools/StatisticsCollectors").subnodes[i].name);
}

for (int i = 1; i <= tableNames.length; i++) {
string tableName = tableNames[i];
//Make sure that there is a file named "Model Run Results" within the same directory as the FlexSim Model.
string fileName = modeldir() + "Model Run Results/" + tableName + ".csv";

Table.query("SELECT * FROM [" + tableName + "]").cloneTo(Table("GlobalTable1"));
exporttable(Table("GlobalTable1"), fileName, 1);
}
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Sebastián Cañas avatar image Sebastián Cañas commented ·
Hi @zachary.h,

Thanks for your answers, however it would work only for Statistics Collectors and the command consider also Chart Templates.

0 Likes 0 ·