question

Przemyslaw Pasich avatar image
0 Likes"
Przemyslaw Pasich asked Przemyslaw Pasich commented

Repainting dashboard windows before exporting to png when switching workspaces

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

  1. treenode screenshots_workspace = Model.find("Tools/Workspaces/screenshots");
  2. 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:

  1. treenode view_node = views().find("active/DockingGUI");
  2. string filePath = modeldir() + "test.png";
  3. 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:

  1. repaintall();
  2. repaintview(view_node);
  3. 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

FlexSim 24.1.0
flexscriptdashboardsworkspaceexport to png
5 |100000

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

1 Answer

Jordan Johnson avatar image
1 Like"
Jordan Johnson answered Przemyslaw Pasich commented

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:

  1. applicationcommand("openworkspace", screenshots_workspace, 1);
  2.  
  3. // Schedule the rest of the script to run 0.5 seconds later
  4. await Delay.realTime(0.5);
  5. // Once the delay finishes, the script continues here
  6.  
  7. // export the screenshot
  8. 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

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