How to set a state table as the state profile of a State Bar?

How to set a state table as the state profile of a State Bar?

royjuventus29
Enthusiast Enthusiast
319 Views
5 Replies
Message 1 of 6

How to set a state table as the state profile of a State Bar?

royjuventus29
Enthusiast
Enthusiast

Hello, I have created a state table and a State Bar. Since there is only one state table, this state table is automatically shown on the state profile of this State Bar. However, when I start simulation, nothing shows on the State Bar. But after I re-select the state table some times, then it works. Here is my code, can anyone solve this problem?

Object utilizationview = maintree().find("project/exec/globals/ChartTemplateDefinitions/State/StateBar");
Object chart_utilization = function_s(dashview, "createGraphWindow", utilizationview, 1);
Group group_utilization = getvarnode(chart_utilization, "replacements").subnodes["Objects"].value;
for(int i = 1; i <= utilization_targets.length; i++)
{
Object q = Model.find(utilization_targets[i]);
group_utilization.addMember(q);
}
treenode statetable = Tools.create("StateTable","Default");

royjuventus29_0-1776280383231.png

 

0 Likes
Accepted solutions (1)
320 Views
5 Replies
Replies (5)
Message 2 of 6

joerg_vogel_HsH
Mentor
Mentor

There are many different states. Some suit for only special objects others are fundamental. FlexSim needs some time to collect used states. This is what you observe. 

0 Likes
Message 3 of 6

royjuventus29
Enthusiast
Enthusiast

Thank you for the answer. It works manually. I would like to achieve it by Flexscript, but it doesn't work with the code I paste. Do you know how to solve the problem?

0 Likes
Message 4 of 6

joerg_vogel_HsH
Mentor
Mentor

"MAIN:/project/library/statistics/StateTable>behaviour/eventfunctions/BuildFromProfile" There you see that a profiile is built from a trackedvariable and also just from a table.

I think you can have somewhere a table in a format that is equal to a state profile table and you update just your own state profile table. 

0 Likes
Message 5 of 6

royjuventus29
Enthusiast
Enthusiast

But I want to link the state table I created into a State Bar of the dashboard. Do you know how to do it?

0 Likes
Message 6 of 6

FelixMoehlmann
Collaborator
Collaborator
Accepted solution

You need to assign the created state table to the statetable node in the "replacements" of the chart node. This will make the chart use the state table for displaying the states. Then you also need to run the "onApply" function of the chart which links the state table to the corresponding Statistics Collector.

You see the state table in the properties drop down because that gets populated with all state tables present in the model. That doesn't mean that the table is linked to the chart.

treenode chart_utilization = ...;
Object stateTable = ...;
getvarnode(chart_utilization, "replacements").subnodes["StateTable"].value = stateTable;
function_s(chart_utilization, "onApply");

You can find stuff like this by exploring the GUI elements. In this case, when selecting a table from the dropdown, the following code is executed:

Screenshot 2026-04-17 110611.png

"applylinks" sets the node value in the "replacements" to the selected table. For the second line we traverse the tree up to the node on which the function_s is called ("c" is the GUI element for which this function is defined, i.e. the next object node above the function node).

Screenshot 2026-04-17 110647.png

This in turn executes the "onApply" on the focus object which is the chart node.