<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Change color of object On State Change in FlexSim Forum</title>
    <link>https://forums.autodesk.com/t5/flexsim-forum/change-color-of-object-on-state-change/m-p/13554761#M58603</link>
    <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;A state is a number. Each state number represents a given state. For example, state 1 is "idle".&lt;/P&gt;&lt;P&gt;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).&lt;/P&gt;&lt;P&gt;You can use the getCategoryName() function to get the state name string from the state number:&lt;/P&gt;&lt;PRE&gt;string toStateStr = current.as(Object).stats.state().getCategoryName(toState);&lt;/PRE&gt;&lt;P&gt;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:&lt;/P&gt;&lt;PRE&gt;current.as(Object).color = Color.fromPalette(toState, "ColorPalette1");&lt;/PRE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;You can also pass the state string, and it will look up a color by that string:&lt;/P&gt;&lt;PRE&gt;string toStateStr = current.as(Object).stats.state().getCategoryName(toState);
current.as(Object).color = Color.fromPalette(toStateStr, "ColorPalette1");&lt;/PRE&gt;&lt;P&gt;If you use this code above, then it will use whatever color is defined for "idle" when the object's state is idle.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1629241180644.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1507054i80B56B126010A264/image-size/large?v=v2&amp;amp;px=999" role="button" title="1629241180644.png" alt="1629241180644.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/42730-color-by-state.fsm" target="_blank"&gt;color_by_state.fsm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;See &lt;A href="https://docs.flexsim.com/en/21.2/Reference/Tools/StateTable/"&gt;The State Table (flexsim.com)&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 17 Aug 2021 23:02:34 GMT</pubDate>
    <dc:creator>philboboADSK</dc:creator>
    <dc:date>2021-08-17T23:02:34Z</dc:date>
    <item>
      <title>Change color of object On State Change</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/change-color-of-object-on-state-change/m-p/13554760#M58602</link>
      <description>&lt;P&gt;&lt;I&gt;[ FlexSim 21.1.4 ]&lt;/I&gt;&lt;/P&gt;&lt;DIV class="fr-view clearfix"&gt;&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;I&lt;SPAN style="color: rgb(65, 65, 65); font-family: sans-serif; font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"&gt; 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!)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: rgb(65, 65, 65); font-family: sans-serif; font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"&gt;I&lt;/SPAN&gt; 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. &lt;/P&gt;&lt;P&gt;I can use a Color Palette in Process Flow to select a color from a range based on the value of a label:&lt;/P&gt;&lt;P&gt;               obj.color = Color.fromPalette(labelname, "palettename")&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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?)&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;Any other suggestions?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 17 Aug 2021 21:53:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/change-color-of-object-on-state-change/m-p/13554760#M58602</guid>
      <dc:creator>clairekruppGhafari</dc:creator>
      <dc:date>2021-08-17T21:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: Change color of object On State Change</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/change-color-of-object-on-state-change/m-p/13554761#M58603</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;A state is a number. Each state number represents a given state. For example, state 1 is "idle".&lt;/P&gt;&lt;P&gt;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).&lt;/P&gt;&lt;P&gt;You can use the getCategoryName() function to get the state name string from the state number:&lt;/P&gt;&lt;PRE&gt;string toStateStr = current.as(Object).stats.state().getCategoryName(toState);&lt;/PRE&gt;&lt;P&gt;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:&lt;/P&gt;&lt;PRE&gt;current.as(Object).color = Color.fromPalette(toState, "ColorPalette1");&lt;/PRE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;You can also pass the state string, and it will look up a color by that string:&lt;/P&gt;&lt;PRE&gt;string toStateStr = current.as(Object).stats.state().getCategoryName(toState);
current.as(Object).color = Color.fromPalette(toStateStr, "ColorPalette1");&lt;/PRE&gt;&lt;P&gt;If you use this code above, then it will use whatever color is defined for "idle" when the object's state is idle.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1629241180644.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1507054i80B56B126010A264/image-size/large?v=v2&amp;amp;px=999" role="button" title="1629241180644.png" alt="1629241180644.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/42730-color-by-state.fsm" target="_blank"&gt;color_by_state.fsm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;See &lt;A href="https://docs.flexsim.com/en/21.2/Reference/Tools/StateTable/"&gt;The State Table (flexsim.com)&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 17 Aug 2021 23:02:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/change-color-of-object-on-state-change/m-p/13554761#M58603</guid>
      <dc:creator>philboboADSK</dc:creator>
      <dc:date>2021-08-17T23:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Change color of object On State Change</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/change-color-of-object-on-state-change/m-p/13554762#M58604</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;Thanks &lt;A rel="user" href="https://answers.flexsim.com/users/206/phil.b.html" nodeid="206"&gt;@Phil BoBo&lt;/A&gt; . 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.&lt;/DIV&gt;</description>
      <pubDate>Tue, 17 Aug 2021 23:58:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/change-color-of-object-on-state-change/m-p/13554762#M58604</guid>
      <dc:creator>clairekruppGhafari</dc:creator>
      <dc:date>2021-08-17T23:58:49Z</dc:date>
    </item>
  </channel>
</rss>

