How to automatically call slot labels with code

How to automatically call slot labels with code

sonia_a
Not applicable
45 Views
6 Replies
Message 1 of 7

How to automatically call slot labels with code

sonia_a
Not applicable

[ FlexSim 21.0.3 ]

Hello Everybody,

I am working on a model in Flexsim in which I would like to automatically create labels in a storage system based on the number of pallets that I store in the slot. I have used this code and it works:

37887-1616500631218.png

If I am not mistaken, with the code above, every slot address has two labels: SKU1 and SKU2.

In another code I would like to select the address of the slots and change the value of the labels that I have created above. I get the address of the slot from labels on my token that indicate the number of corridor, level, bay etc. and based on a condition I decide whether to assign the value "token.UDC.sku" to the slot label SKU1 or SKU2. If I am storing the first pallet, then the label SKU1 of that slot should be equal to the SKU of the pallet (token.UDC.sku). If I am storing the second pallet, I would like to set the value of the slot label SKU 2 equal to the SKU of the pallet (token.UDC.sku).

37896-1616500117943.png

If I have three stored pallets I would need three slot labels (SKU1 SKU2 SKU3) and I would need to expand the code above to cover the condition if(token.cpal == 3). Since the number of pallets in the slot can vary, I wanted to automatize this system and I have tried to write the code below.

37875-1616500497510.png

The problem is in the way I call the label of the slot. If I call it directly by its name (SKU1 or SKU2) it works but if I use the last code that I showed, it does not work because I cannot refer to the label of the slot address by using "concat...".

Does anybody know how to solve this problem and how to refer to a slot label without directly writing its name in the format .labelname?

Thank you so much for your help!

0 Likes
Accepted solutions (1)
46 Views
6 Replies
Replies (6)
Message 2 of 7

jason_lightfootVL7B4
Autodesk
Autodesk
Accepted solution

object.labels["SKU"+mynum].value



0 Likes
Message 3 of 7

sonia_a
Not applicable

Hi Jason, Thank you for your answer!

Could I kindly ask you how you would put that part in the code I have shown above? I have tried this but it does not work.

37876-1616504937345.png

I have also tried in this and it doesn't work either

37898-1616505207994.png Do you know how can I use what you suggested on a slot like in my case?

Thank you so much for your help, it is really appreaciated!

0 Likes
Message 4 of 7

jason_lightfootVL7B4
Autodesk
Autodesk

You need to have the label on the slot first before you can use that expression.

For example - this code will put a label "SKU4" on every slot and set it to he index in the array of all slots.

Array slots=Storage.system.querySlots("");
for (int n=slots.length;n>0;n--){
    slots.labels.assert("SKU"+4);
    slots.labels["SKU"+4].value=n;
}


0 Likes
Message 5 of 7

sonia_a
Not applicable

Thank you a lot!

There is still something that I do not understand. In my code I have this part (picture) which already creates the labels on the slots. It creates them in the Storage System Properties, so theoretically I did have the labels on the slots before I used your expression. I can't use the expression Storage.system.getslot("string address") together with your suggestion (object.labels["SKU"+mynum].value ), even if I already have the labels on my slots. Do you have any idea why that is?

37877-1616512467332.png

0 Likes
Message 6 of 7

jason_lightfootVL7B4
Autodesk
Autodesk

Your code will add the label as an indexable property of the slots and can then be referenced in the slot queries without using the notation: WHERE slot.mylabel=x instead you can just use WHERE mylabel=x . That is meant to be faster in very large storage systems. The slots added that way allow them to return the default value even when they have not been set.

When you use the slot label painter tool the, the values painted are written to the slots in the same way that the assert command writes to the slot, but with the addition of the reset value. Since there is then a value on the slot, this is returned rather than the global default value you set up in the Storage System gui (using your function_s call).

Normally this would be simpler since mostly people don't need to use the assert or labels[""] notations - they can just use slot.labelname - it's just that because you want them to be string variables that the given notation is needed.


0 Likes
Message 7 of 7

sonia_a
Not applicable

Thank you for your answer!

0 Likes