question

Claire Krupp avatar image
0 Likes"
Claire Krupp asked Claire Krupp commented

Change color of object On State Change

I want to change the color of an object, e.g. Processor, whenever it changes State. I have created a Color Palette for state colors which works with the State Gantt charts etc, so I thought I could just create a Trigger On State Change and there would be a "Change Color" option in the drop down menu, but there are no visual options at all. (in fact the only option is "do nothing" LOL!)

I know how to change the color of an Object e.g. obj.color = Color.aqua, and I am doing that in Process Flow at various steps in the logic, but it is a pain to have to do that manually every time.

I can use a Color Palette in Process Flow to select a color from a range based on the value of a label:

obj.color = Color.fromPalette(labelname, "palettename")

But I can't figure out the syntax to convert the "toState" in the Trigger code, which is an integer, into a string with the name of the associated state.

The manual says that there is a State Table which is accessible from the Toolbox, but I have searched and cannot find one. (Is this new?)

The only thing I can think of is to create a tiny section of Process Flow to create a token on Change of State, and then perhaps I can use the Change Visual to do it?

Any other suggestions?


FlexSim 21.1.4
flexsim 21.1.4color palettechange coloronstatechange
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

Phil BoBo avatar image
0 Likes"
Phil BoBo answered Claire Krupp commented

A state is a number. Each state number represents a given state. For example, state 1 is "idle".

The state tracked variable that tracks an object's states is a categorical tracked variable where the categories are the string names of the state, such as "idle" (1, STATE_IDLE) or "waiting for operator" (9, STATE_WAITING_FOR_OPERATOR).

You can use the getCategoryName() function to get the state name string from the state number:

string toStateStr = current.as(Object).stats.state().getCategoryName(toState);

A Color Palette will return colors for any variant, including either strings or numbers. You can pass the state number directly, and it will look up a color by that number:

current.as(Object).color = Color.fromPalette(toState, "ColorPalette1");

If you use the code above, then it will be colored based on the number value in the color palette. For example, when the object is idle, it will be colored based on the number 1.

You can also pass the state string, and it will look up a color by that string:

string toStateStr = current.as(Object).stats.state().getCategoryName(toState);
current.as(Object).color = Color.fromPalette(toStateStr, "ColorPalette1");

If you use this code above, then it will use whatever color is defined for "idle" when the object's state is idle.

1629241180644.png

color_by_state.fsm

In FlexSim 21.2, we introduced State Tables to define display names and utilization status for given state numbers so that you can define that information in one place and use it on multiple charts instead of having to define it on each state chart like you do in FlexSim 21.1. That's not really related to this issue of coloring by state. You can already define colors via Color Palettes in FlexSim 21.1 or 21.2.

See The State Table (flexsim.com)


1629241180644.png (264.9 KiB)
color-by-state.fsm (51.2 KiB)
· 1
5 |100000

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

Claire Krupp avatar image Claire Krupp commented ·
Thanks @Phil BoBo . I figured out I could just make a copy of my Palette that uses numbers instead of names and then it works fine, however I am very interested to know how to get the name through the getCategoryName. Thank you.
0 Likes 0 ·