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:

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

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

  1. treenode AnActiveDashboard = views().find("active>Documents/Dashboard/1+");
  2.  
  3. if (AnActiveDashboard != NULL) {
  4. function_s(ownerobject(AnActiveDashboard), "exportData", 1);
  5. }

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.

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.

  1. treenode link = node("..>objectfocus+", c);
  2. /**Custom Code*/
  3. Object current = ownerobject(c);
  4.  
  5. Array tableNames;
  6. for (int i = 1; i <= Model.find("Tools/StatisticsCollectors").subnodes.length; i++){
  7. tableNames.push(Model.find("Tools/StatisticsCollectors").subnodes[i].name);
  8. }
  9.  
  10. for (int i = 1; i <= tableNames.length; i++) {
  11. string tableName = tableNames[i];
  12. //Make sure that there is a file named "Model Run Results" within the same directory as the FlexSim Model.
  13. string fileName = modeldir() + "Model Run Results/" + tableName + ".csv";
  14.  
  15. Table.query("SELECT * FROM [" + tableName + "]").cloneTo(Table("GlobalTable1"));
  16. exporttable(Table("GlobalTable1"), fileName, 1);
  17. }
· 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.