Repainting dashboard windows before exporting to png when switching workspaces

Repainting dashboard windows before exporting to png when switching workspaces

pasichp
Not applicable
31 Views
4 Replies
Message 1 of 5

Repainting dashboard windows before exporting to png when switching workspaces

pasichp
Not applicable

[ FlexSim 24.1.0 ]

Context: I want have a workspace set up with a number of dashboard windows each of which will be exported to a .png. Then switch into that workspace and run that export using one user command. The desired result:

test2.png

Problem: after I switch to another workspace using

treenode screenshots_workspace = Model.find("Tools/Workspaces/screenshots");
applicationcommand("openworkspace", screenshots_workspace, 1);

the dashboard windows don't manage to paint the contents of their graphs before the consequent exports to .pngs take place:

treenode view_node = views().find("active/DockingGUI");
string filePath = modeldir() + "test.png";
viewtofile(view_node, filePath);

and that results in exporting screenshots with empty graphs:

test.png

I tried the following ways of forcing the paint instruction to execute before the exports:

repaintall();
repaintview(view_node);
msg("", "Desperate attempt at giving the paint instruction more time to execute.");

However, none of them worked.

Any ideas how to resolve this problem? I am attaching a model that recreates this issue.

force repaint before screenshotting.fsm

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

JordanLJohnson
Autodesk
Autodesk
Accepted solution

Repainting doesn't work because charts are managed in a separate process. The trick is to have the script wait for a bit before exporting:

applicationcommand("openworkspace", screenshots_workspace, 1);

// Schedule the rest of the script to run 0.5 seconds later
await Delay.realTime(0.5);
// Once the delay finishes, the script continues here

// export the screenshot
viewtofile(...);

Usually, an await handles waiting for the model clock. But in this case, await waits for the real clock to move.

https://docs.flexsim.com/en/24.1/Reference/CodingInFlexSim/WritingLogic/WritingLogic.html#coroutines

.


Jordan Johnson
Principal Software Engineer
>

Message 3 of 5

pasichp
Not applicable
Hi Jordan, thanks for the reply - with your suggestion it works as intended on the sample model. One thing I'm curious about: would that approach be prone to a "racing" problem? If I had a dashboard with numerous elements and my PC takes longer than the hard-coded 0.5s painting them, would that result in the export activating prematurely giving improperly rendered pngs?
0 Likes
Message 4 of 5

jason_lightfootVL7B4
Autodesk
Autodesk

Doesn't this question answer itself? If the time to render is longer than 0.5 seconds then you will not get a completely rendered view at that time.

0 Likes
Message 5 of 5

pasichp
Not applicable

I saw that interjecting with the msg() halted both the export statement and the rendering of the graphs - so I figured FlexSim cannot do graph rendering as a parallel, independent process. And so I hoped that introducing a realtime delay makes FlexSim go "since the user command is instructing me to wait anyway, let me grab the next thing on to-do list (rendering all the graphs) and complete that before I come back to the user command and see whether those 0.5s passed" - with that approach, the graphs would render before exporting no matter the delay length.

One way or another, thank you for answering my questions! I appreciate it. My problem was solved.

0 Likes