How To Set Slot Value Using Variable Label Name

How To Set Slot Value Using Variable Label Name

stan.e.davis
Advocate Advocate
368 Views
7 Replies
Message 1 of 8

How To Set Slot Value Using Variable Label Name

stan.e.davis
Advocate
Advocate

[ FlexSim 22.2.0 ]

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

0 Likes
Accepted solutions (1)
369 Views
7 Replies
Replies (7)
Message 2 of 8

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

0 Likes
Message 3 of 8

stan.e.davis
Advocate
Advocate

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
Message 4 of 8

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution

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));




Matthew Gillespie
FlexSim Software Developer

0 Likes
Message 5 of 8

joerg_vogel_HsH
Mentor
Mentor

@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
Message 6 of 8

Matthew_Gillespie
Autodesk
Autodesk

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


Matthew Gillespie
FlexSim Software Developer

0 Likes
Message 7 of 8

joerg_vogel_HsH
Mentor
Mentor
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
Message 8 of 8

Jeanette_Fullmer
Community Manager
Community Manager

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