question

shanice.c avatar image
0 Likes"
shanice.c asked shanice.c commented

Change Object Color using process flow

Hi, how to not let all token flowing together, I have put several processors into a Group, and I've used match value to match token and 3D object. I'm using process flow Change Visual activity to change Processor color when on entry event, I want it to change back to its original color in on exit event. Thank you.

ChangeColor.fsm

FlexSim 20.0.10
change visual
changecolor.fsm (39.7 KiB)
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

Matthew Gillespie avatar image
0 Likes"
Matthew Gillespie answered shanice.c commented

You are using an Object process flow that is attached to all the processors so you don't need to acquire a processor from the group or listen to events on the whole group or even match anything in the wait for event activities. Since you're using an Object flow a new instance of the flow is created for each processor attached and so you'll end up with one token per processor and you can simply refer to the attached processor using current. So I removed all the unnecessary activities and replaced all the references to token.EQ with current.

Secondly, your model has an issue where if you reset the model while the object has its color changed then the object will permanently be the new color. To avoid this I added the originalColor label to the processor and added an OnReset trigger to the processors to restore the object's color from the originalColor label.

changecolor_working.fsm


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

shanice.c avatar image shanice.c commented ·

Hi,@Matthew Gillespie May I ask how do you get originalColor value in the label for the first time?

1633229763591.png

I set label first in order to get that value.1633229891205.png

But in your attached model, I couldn't find how to get the rbga. I'm not sure if it's redundant to do this?

0 Likes 0 ·
1633229763591.png (12.6 KiB)
1633229891205.png (34.6 KiB)
Matthew Gillespie avatar image Matthew Gillespie ♦♦ shanice.c commented ·

@Fiona C

I opened the script window and ran some code like this to store the object's color on a label:

Object processor = Model.find("Processor1");
processor.originalColor = processor.color.as(Array);

You don't want to set the label in On Reset. If you do that you're going to override the object's original color with its current color, which defeats the purpose of storing off the object's original color in the first place.

Think about this situation:

  1. You run the model until the processor changes to lime green.
  2. You reset the model. (The processor is still lime green)
  3. In On Reset you take processor's current color (lime green) and store that on the processor's originalColor label.

The originalColor label is now lime green and the processor will never change to any other color.

1 Like 1 ·
shanice.c avatar image shanice.c Matthew Gillespie ♦♦ commented ·
@Matthew Gillespie Thanks for your detailed explanation. I could understand how this works.
0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel shanice.c commented ·

Try just current.color to get an array of values.

If this doesn’t work for you may get access by method getProperty.
Please look into the tree. If the structure seems to be a container with subnodes, you can make them to an array by method.

flexscript-class-treenode.png
Naturally current is replaced by a reference to the color container node.

0 Likes 0 ·