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

string mylabelname;
mylabelname = "Apples";

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

slot.mylabelname = 5;

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

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.

Jeanette F avatar image Jeanette F ♦♦ commented ·

Hi @Stan Davis, was one of Matthew Gillespie's or Joerg Vogel's answers helpful? If so, please click the "Accept" button at the bottom of the one that best answers your question. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

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

string myLabelName = "Apples";
string code = "Model.find(\"Rack1\").as(Storage.Object).getSlot(1, 1, 1).as(Storage.Slot).labelName = 5;";
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 Joerg Vogel commented ·

@Matthew Gillespie , I think you can set a label value even by setting a node value. Then you would use a subnode reference to get the node and assign a value to him.

slot.labels.subnode[myLabelName].value = 5; 
slot.as(treenode).labels[myLabelName].value = 5;

maybe even shorter

slot.labels[myLabelName].value = 5;

I’ll test it later in the day.

slotlabel-by-string-variable-read-write.jpg

0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Joerg Vogel commented ·

@Joerg Vogel

This partially works, but the help manual warns you not to do this since the Storage.Slot class does some extra managing of labels when you set a label on it that doesn't happen if you set the label using the treenode class.
0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel Matthew Gillespie ♦♦ commented ·
Thank you, @Matthew Gillespie ,

then we need methods to update slot labels for rack cells and a single slot. Or we need a method to update this special management, if a label is changed on a treenode level.

As discussed earlier indexing labels is only relevant, if slot label values have a static character. Then there must be existing a property to dealing with this attribute.

0 Likes 0 ·
Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Stan Davis commented
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.

Stan Davis avatar image Stan Davis commented ·

To clarify, you recommend using the assert method?

In Storage.Slot.labelProperties help section, it states..

For slot labels, you MUST access the label through this dynamic properties syntax. You should not use syntax that accesses label nodes directly in the tree (like

slot.labels.assert("SKU").value = 5;

). The storage system may manage an index of slot label values for quick lookup. This index is only updated properly when you use the dynamic property syntax to set label values.

If I understand your response, if I am NOT changing the values during the sim run, then using the assert method is not an issue. Is the index updated if I apply values using this method on a model reset trigger?


0 Likes 0 ·