question

William Proctor avatar image
1 Like"
William Proctor asked Jordan Johnson commented

Automatic Exporting of Dashboard Image

I would like to quickly export all of the dashboard images for experiments. I know how to export the raw data used to generate the images and know that the images can be manually exported to the PNG format. Is there a way, however, to export the image to a file automatically at the end of a run?

FlexSim 16.1.2
exportautomaticpngimage
5 |100000

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

Sam Stubbs avatar image
1 Like"
Sam Stubbs answered Jordan Johnson commented

So we were able to achieve this by exploring the structure of the dashboard properites panel, and looking at the Save as PNG file. In there it calls the function_s() function which calls a predefined "savePNG" function. So when we took it apart we came up with the following code.:

treenode view = node("/1>Documents/Dashboard/1+/..",views());
function_s(ownerobject(view),"savePNG");

Where the treenode view is a reference to the view of the dashboard. The function_s(ownerobject(view),"savePNG"); executes a function that will bring up a file save window where you can name and save your PNG file.

So call this code at some point in your logic at the end of your runtime, and then when it hits that point it will pop up with the option for you to save the view of your file as a PNG. I've attached the model below with the code snippet in it, so you can try it.

testpngmodel.fsm


testpngmodel.fsm (13.0 KiB)
· 10
5 |100000

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

jing.c avatar image jing.c commented ·

Hi, Sam.

Your model works well! But can we save the PNG with some specified name in code instead of bringing up the file save window and naming them one by one?

0 Likes 0 ·
Noah Z avatar image Noah Z jing.c commented ·

Having a method to specify the name via code rather than interacting every time with a dialog box would be very useful. Is there any guidance on how to do this?

@Sam Stubbs

0 Likes 0 ·
Jacob Gillespie avatar image Jacob Gillespie ♦ Noah Z commented ·

@Noah Zenker, @jing.chen

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);
2 Likes 2 ·
Show more comments
William Proctor avatar image William Proctor commented ·

Sam - Thanks for your help with this!

0 Likes 0 ·
Noah Z avatar image Noah Z commented ·

@Sam Stubbs

Is the method you described above still valid in FS18? I tried to run code above and it doesn't seem to do anything anymore.

0 Likes 0 ·
Sam Stubbs avatar image Sam Stubbs ♦ Noah Z commented ·

That's a great question. I know they've made some substantial changes to the Dashboard. It looks like the save to PNG has made some changes as well. @jordan.johnson Do you know how you could accomplish this is 2018?

0 Likes 0 ·
Jordan Johnson avatar image Jordan Johnson ♦♦ Sam Stubbs ♦ commented ·

I used the code given above in 18.0, and it worked fine. The code does assume a couple things, though. First, the path must be correct, with escaped slashes. Second, the dashboard must be open.

While there was a big overhaul to the dashboard library, the dashboard itself didn't change between versions 17 and 18, so this method ought to work.

1 Like 1 ·
Show more comments
Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered William Proctor commented

Since the capture screen shortcut key "p" was lost in previous Flexsim versions sometime in the past, you can still use external programs with the command:

runprogram(str commandline); // runprogram("c:/myprogram.exe")

For example the program irfanView has some command line options to capture the screen or a rectangle area and save the area in different graphical formats:

i_view32.exe /capture=2 
/convert=c:\capture_$U(%d%m%Y_%H%M%S).jpg

This example from the manual faqs save the screen with a time stamp in the file name.

· 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.

William Proctor avatar image William Proctor commented ·

Thanks Jorg! This will be helpful! - Bill

0 Likes 0 ·