question

gilbert jerald avatar image
1 Like"
gilbert jerald asked Jordan Johnson commented

How to add or remove group from dashboard dynamically using code?

Hi,

In my model, I have a group called "OperatorGroup" where 3 operators are been added to that group and it is been attached to the dashboard to collect the utilization stats.

In my case, if the number of object in the group is "zero" how to remove that group from the dashboard through code. and how to re-add if the number of object in the group is greater than "zero".

I am using legacy charts (state bar chart) to display group statistics.

Thanks

FlexSim 18.1.1
dashboard display
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
0 Likes"
Jordan Johnson answered Jordan Johnson commented

Instead of adding the toolbox group to the chart, I would use the legacy chart Group option. Instead of removing the group, you should remove everything from the chart on reset. Here is example code that belongs in the model's OnReset trigger:

string chartName = "State Bar"; // you may need to change the name here
treenode chart = model().find("Tools/Statistics/" + chartName); 

// Remove any objects from the chart
getvarnode(chart, "objects").subnodes.clear();

// Go through the groups, and add the correct objects
Array groupNames = ["Group1", "Group2"]; // put all group names you want in this array
for (int i = 1; i <= groupNames.length; i++) {
	string groupName = groupNames[i];
	Group group = Group(groupName);
	Array members = group.toFlatArray();
	for (int j = 1; j <= members.length; j++) {
		treenode member = members[j];
		treenode memberLink = function_s(chart, "addMember", member);
		memberLink.name = groupName;
	}
}
· 2
5 |100000

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

Albert L avatar image Albert L commented ·

Hi Jordan, I looked up function_s on the command reference and found the following information:

"For developer use. Executes code associated with the node found in the object's eventfunctions group having the specified name. For a list of the pre-defined system level events in FlexSim refer to function_n() command documentation."

Where can I find the list of object eventfunctions? Appreciate the help.

0 Likes 0 ·
Jordan Johnson avatar image Jordan Johnson ♦♦ Albert L commented ·

The list of possibilities for the second parameter of function_s depend on what you pass as the first parameter. The first parameter should be an object. You can look in that object's eventfunctions node, or in the eventfunctions node of the class in the library. Once you find the list of functions, it is up to you to read the code and determine what needs to be passed in, or whether it will work to call that function at all.

0 Likes 0 ·