Export All Dashboards to CSV using FlexScript

Export All Dashboards to CSV using FlexScript

sebastian_canas9DYX7
Collaborator Collaborator
21 Views
4 Replies
Message 1 of 5

Export All Dashboards to CSV using FlexScript

sebastian_canas9DYX7
Collaborator
Collaborator

[ FlexSim 25.0.2 ]

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!

0 Likes
Accepted solutions (1)
22 Views
4 Replies
Replies (4)
Message 2 of 5

zac_higleyQBKLZ
Autodesk
Autodesk

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.name);
}

for (int i = 1; i <= tableNames.length; i++) {
string tableName = tableNames;
//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);
}
Message 3 of 5

logan_gold
Community Manager
Community Manager
Accepted solution

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.

Message 4 of 5

sebastian_canas9DYX7
Collaborator
Collaborator
Thanks! @Logan Gold!
0 Likes
Message 5 of 5

sebastian_canas9DYX7
Collaborator
Collaborator
Hi @zachary.h,

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

0 Likes