question

Jacob Noltner avatar image
1 Like"
Jacob Noltner asked Jeanette F commented

How to automate saving off all Dashboards as .pngs

We are trying to write a script that save all of our dashboards to the same location as the .fsm as .png files. parts of the attached code seem to work individually but as a whole something is not working. We used (Automatic Exporting of Dashboard Image - FlexSim Community) this string for to help write most of the code in "OnRunStop".

FlexSim 16.2.2
FlexSim 22.1.2
dashboardsscriptingexport all dashboards to html.png
· 6
5 |100000

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

Jacob Noltner avatar image Jacob Noltner commented ·

Model Uploaded

testpngmodel.fsm

0 Likes 0 ·
testpngmodel.fsm (13.0 KiB)
Jeanette F avatar image Jeanette F ♦♦ Jacob Noltner commented ·
Note: This is a 16.2 model which has reached its end of life.


We will be happy to still help you, but you should contact your local distributor to upgrade your software.
0 Likes 0 ·
Jacob Noltner avatar image Jacob Noltner Jacob Noltner commented ·

Apolgies,

I had some saving issues yesterday. This is the file I meant to upload. The "view" doesn't seam to change the selected Dashboard like it should and the save dashboard doesn't work either...

testpngmodel2.fsm

0 Likes 0 ·
testpngmodel2.fsm (43.7 KiB)
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Jacob Noltner commented ·

This node doesn't exist:

node("/1>Documents/"+DashName+"/1+/..",views())

If you look in the views tree you'll see that you're missing the "Dashboard" folder and also that the nodes inside that have no name.

To loop through all the dashboards you would want to change your code to something like this:

treenode graphPanel;
string DashName;
string filePath;
treenode activeDashboards=views().find("active>Documents/Dashboard");
treenode dashboard;
forobjectlayerunder(activeDashboards)
{
    dashboard= node("+/~",a);
    DashName = dashboard.name;
   // applicationcommand("activatedockedview", dashboard);

    graphPanel = node("GraphPanel", dashboard);
    filePath = "C:\\Desktop\\"+DashName+".png";

    for (int i = 1; i <= content(graphPanel); i++) {
        treenode widget = rank(graphPanel, i);
        if (getvarnum(widget, "showingSizers")) 
            function_s(widget, "hideSizers");
    }

    viewtofile(graphPanel, filePath);
}

For me this only works if all the dashboards are visible which may be impractical.

0 Likes 0 ·
Show more comments
Jeanette F avatar image Jeanette F ♦♦ commented ·

Hi @Jacob Noltner, was one of Joerg Vogel's or Jeanette F's answers helpful? If so, please click the "Accept" button at the bottom of the one that best answers your question. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·
Jeanette F avatar image
0 Likes"
Jeanette F answered Jeanette F commented

Hello @Jacob Noltner,

The problem with the other solutions is the timing of the charts being drawn before the file is exported. We could not come up with a consistent solution. The other option besides exporting as a PNG is to export HTML. This is a better method when automatically exporting the charts because all the data is exported with the file, so it doesn't need to wait for things to be drawn. The charts will be drawn later when the HTML file is opened.

testpngmodel4a_2.fsm


· 3
5 |100000

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

Jacob Noltner avatar image Jacob Noltner commented ·

Jeanette thank you for you time with this. The main reason we are thinking about moving away from the print all HTML files was because depending on the size and shape of each dashboard it can be hard to predict the layout/shape the HTML file will take. Because we are typically creating reports for our clients in either MS Word or as a .PDF we end up doing a very tedious task of screen shotting each section of the combined HTML and pasting them into our reports. If we end up rerunning the scenario the copy paste task would have to be done all over again. Our thought was instead was to make more dashboard that do not require scrolling and print all to PNG as they seem to be the screen shot we are typically after. I think I will post to the development page that dashboards be exportable to a more report-friendly format in the future as that is really the end goal we are after.

Another reason we were thinking about moving away from the HTML export was reliability. I'd estimate 1 in every 10 exports for the last project I was on the HTML would export blank cells when the dashboard had values. There were a few times we didn't catch the bad export until after the FS file was closed and would required a lengthy rerun of the simulation just to export the bad html file again.

Bad HTML Save.bmp

0 Likes 0 ·
bad-html-save.bmp (1.7 MiB)
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Jacob Noltner commented ·
If you have the screen space to have the dashboards open all the time then the export will work. Let us know if you want us to help you set that up (since it should have been writing png files and you indicated it was having trouble with that).
0 Likes 0 ·
Jeanette F avatar image Jeanette F ♦♦ Jacob Noltner commented ·
Hello @Jacob Noltner,

We have talked with the developers about this. They believe what they created with the HTML that I shared with you will be more reliable. However, the reality is that they did not intend for a use like this. This can be placed as an idea for them to improve upon FlexSim.

0 Likes 0 ·
Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered

There are existing models, which are still updating line charts after hitting stop or reset in dashboard control. So I am not convinced, that a screen shot is an accurate solution to get report data.
BUT if it is still working for you, you can automate taking screen shots by command line driven external programs. You would call them for within FlexSim.

5 |100000

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

Jeanette F avatar image
0 Likes"
Jeanette F answered Jeanette F commented

Hello @Jason Lightfoot,

mine and @Jason Lightfoot answers are similar so we worked on this together for a short amount of time. It ended up working on my computer but not his. Could you let us know if the following code works for you?

treenode graphPanel;
string DashName;
string filePath;
treenode activeDashboards=views().find("active>Documents/Dashboard");
treenode dashboard;
forobjectlayerunder(activeDashboards)
{
    dashboard= node("+/~",a);
    DashName = dashboard.name;
    applicationcommand("activatedockedview", dashboard);
    for(int j =1; i<=100; i++){
    for(int k =1; k<=100; k++){
    
    }
    }
 
    graphPanel = node("GraphPanel", dashboard);
    filePath = "C:\\Users\\jeanette.fullmer\\Desktop\\"+DashName+".png";
 
    for (int i = 1; i <= content(graphPanel); i++) {
        treenode widget = rank(graphPanel, i);
        if (getvarnum(widget, "showingSizers")) 
            function_s(widget, "hideSizers");
    }
 
    viewtofile(graphPanel, filePath);
}
· 4
5 |100000

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

Jacob Noltner avatar image Jacob Noltner commented ·

testpngmodel3.fsm

I tired some things and commented the code but could not get it to work...

0 Likes 0 ·
testpngmodel3.fsm (43.5 KiB)
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Jacob Noltner commented ·
Did it generate the files but with some of them blank? I could only get it to work by having the dashboards docked/arranged so that all charts were visible at the same time.
0 Likes 0 ·
Jacob Noltner avatar image Jacob Noltner Jason Lightfoot ♦♦ commented ·
The best I can do is get the dashboards to flip thru as I step thru the loop in the code. no .pngs are created blank or otherwise. If setting up a screen share meeting is helpful since it seem like some computers are having more success than others, I am all for that. If you do send a meeting invite please include Tyler Morrison as optional as well. Thanks!!
0 Likes 0 ·
Show more comments
Jeanette F avatar image
0 Likes"
Jeanette F answered

The post that you linked provided a few methods to create the image. I found that Jacob Gillespie's answer worked.

treenode view = node("/1>Documents/Dashboard/1+/..",views());
treenode graphPanel = node("GraphPanel", ownerobject(view));
string filePath = "C:\\Users\\user.name\\Desktop\\img.png";
 
// This hides the sizers, you could remove this
for (int i = 1; i <= content(graphPanel); i++) {
treenode widget = rank(graphPanel, i);
if (getvarnum(widget, "showingSizers")) 
function_s(widget, "hideSizers");
}
 
// This saves the dashboard as a png
viewtofile(graphPanel, filePath);
5 |100000

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