question

Stan Davis avatar image
0 Likes"
Stan Davis asked Jeanette F commented

How To Set Slot Value Using Variable Label Name

Looking for correct syntax to set label value using a variable in place of the label name.

For example..

  1. string mylabelname;
  2. mylabelname = "Apples";

This obviously does not work as it creates a label called "mylabelname"...

  1. slot.mylabelname = 5;

Per help, should not access label nodes directly like this..

  1. slot.labels.assert(mylabelname).value = 5;


So how do I do this?

Thanks

FlexSim 22.2.0
scriptslotvariables
· 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.

Matthew Gillespie avatar image
0 Likes"
Matthew Gillespie answered Joerg Vogel commented

Could you give us a little more detail/context on what you're doing? If you have a use case that we don't have good support for we might need to look into improving the slot API.

If you happen to be setting the label on all the slots in the object/bay/level you can use one of the versions of the setSlotLabels() method that lets you pass in the name of the label:

Storage.Object.setSlotLabels()

Stoage.Bay.setSlotLabels()

Storage.Level.setSlotLabels()

Otherwise, it's a little tricky to use, buy you could try the executestring command. You dynamically create the FlexScript you want to run as a string and then call executestring() on it.

  1. string myLabelName = "Apples";
  2. string code = "Model.find(\"Rack1\").as(Storage.Object).getSlot(1, 1, 1).as(Storage.Slot).labelName = 5;";
  3. executestring(code.replace("labelName", myLabelName));


· 3
5 |100000

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

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Stan Davis commented
  1. slot.labels.assert(mylabelname,5).value = 4;

5 is an initial value, if label does not exist. If it exists the label gets assigned value 4. Obviously both values would be equal, but to describe it, I have chosen different values.

If a label is indexed, then it means, that it gets a static character. Indexed nodes get faster evaluated, but any change results in a new indexing and this take some time because all slots are checked if this label exists.
You would use an indexed label for racks that represent static data like city, country, plant. Labels, which values might change while a model runs, you wouldn’t set an attribute to be indexed.

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