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.