question

Jeremy R avatar image
1 Like"
Jeremy R asked Phil BoBo edited

​Cleaning up orphaned Statistics objects

I have noticed that in my Model's tree, the Statistics folder is polluted with unused Statistics objects.
These appear to correspond to every graph we have ever created in the model, including graphs that have been deleted and graphs that were on dashboards which have been deleted.

Looking through the Statistics objects themselves, there doesn't appear to be any way to distinguish which Statistics objects are used and which are not from the objects' properties. The only way I can see to determine this is by manually going through every dashboard and identifying which Statistics objects are actually used on it.

Is there some way to remove all unused Statistics objects from the model?

It's mostly an issue because I'm trying to eradicate a particular term from my model, and when searching for uses of it I'm getting a bunch of Statistics object using that term, which appear to simply be false positives since they're ostensibly unused. I don't want to rename objects directly from the tree, so I'm mostly just stuck with the names they had when they were deleted.

FlexSim 18.2.3
statisticstree
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
2 Likes"
Jordan Johnson answered Phil BoBo edited

You can close all your dashboards, then run this script:

  1. treenode statisticsFolder = Model.find("Tools/Statistics");
  2. Array usedStatsObjects;
  3. var dashboards = Model.find("Tools/Dashboards").subnodes;
  4. for (int d = 1; d <= dashboards.length; d++) {
  5. var widgets = dashboards[d].subnodes;
  6. for (int w = 1; w <= widgets.length; w++) {
  7. Object widget = widgets[w];
  8. treenode saver = widget.attrs.find("saver");
  9. treenode storedNode = widget.attrs.find("stored");
  10. if (saver && saver.value == "DashboardWebStatGraph" && storedNode) {
  11. var storedLinks = storedNode.subnodes;
  12. for (int s = 1; s <= storedLinks.length; s++) {
  13. treenode linkedNode = storedLinks[s].find("+/~");
  14. if (linkedNode && linkedNode.up == statisticsFolder) {
  15. usedStatsObjects.push(linkedNode);
  16. }
  17. }
  18. }
  19. }
  20. }
  21. var statsObjects = statisticsFolder.subnodes;
  22. for (int i = 1; i <= statsObjects.length; i++) {
  23. treenode statsObject = statsObjects[i];
  24. if (usedStatsObjects.indexOf(statsObject) <= 0) {
  25. print(statsObject);
  26. // statsObject.destroy();
  27. }
  28. }

The script looks for any Statistics Object that isn't linked to a dashboard chart. Note that the script currently just prints those charts to the Output Console. You will need to change it to actually destroy the orphaned charts.

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