question

a600 avatar image
1 Like"
a600 asked Felix Möhlmann commented

Reset Label via FlexScript

We are trying to assign labels of integer value to processors via FlexScript. See code below.

We accidentally ran this code multiple times. Now, the type of the label is an array with multiple duplicate integers.

We want to revert back to the original integer value we assigned. We also want these labels to be static. How should we go about this?


See the original code:

clearconsole;


int numRows = Group("Sourcing Group").length;

Array myGroups = ["Sourcing Group", "Conditioning Group", "Finishing Group", "Packing Group", "Distribution Group"];


for (int i = 1; i <= myGroups.length; i++) {

for(int j = 1; j <= numRows; j++){

Object processor = Group(myGroups[i]);

processor.location = j;

print(j);

}

print(i);

}

FlexSim 25.1.0
flexscriptduplicate
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

Felix Möhlmann avatar image
1 Like"
Felix Möhlmann answered Felix Möhlmann commented

location is an object property. If you want to set a label with that name, you have to use "processor.labels["location"].value = ...". It is recommended to avoid using such names. Using a capital letter at the start of label names makes sure that they do not coincide with property names.

The processor variable in your code is assigned a reference to an entire group, instead of a single object. If I understood your goal correctly (number the objects in each group from 1 to N), then the code should look like the following,

Array myGroups = ["Sourcing Group", "Conditioning Group", "Finishing Group", "Packing Group", "Distribution Group"];
Group curGroup; for(int i = 1; i <= myGroups.length; i++) {     curGroup = Group(myGroups[i]);     for(int j = 1; j <= curGroup.length; j++)     {         Object processor = curGroup[j];         processor.Location = j;     } }
· 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.

Alixe avatar image Alixe commented ·
Thank you for your answer! Does this code create the label Location, or does it assume it already exist? Is there a way to delete the original label location for all the objects in the group at once? Instead of clicking on the properties and deleting 1 by 1?
0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann Alixe commented ·

The dot-syntax "object.labelName = ..." will create the label if it does not exist or overwrite the value if it does. The long form would be "processor.labels.assert("Location").value = ..."

To remove the other label you can add this into the innermost for-loop. With "object.labels["labelName"]" you access the label node rathen than the value. This allows you to delete the node (or change its name, among other things).

if(objectexists(processor.labels["location"]))
{     processor.labels["location"].destroy(); }
1 Like 1 ·
Alixe avatar image Alixe Felix Möhlmann commented ·
Thank you, that worked!

An additional question: can we set maximum content for processors using a reference to a Global Table? I tried but it says the field on accepts numbers.

Could we use Flexscript for this?

0 Likes 0 ·
Show more comments