question

ROBIN avatar image
0 Likes"
ROBIN asked ROBIN commented

Triggers and SendToPort using code (flexscript)

I have one processor that processes many types of items. I want for each type that enters the processor goes out with another label value. I know this can be done using On Entry trigger but I couldn't do it with code using flexscript.

I also need to send to port depending on the new label value. using flexscript as well.

Thank you in advance.

FlexSim 23.0.15
flexscriptcodetriggers
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

Sri_vikas K avatar image
0 Likes"
Sri_vikas K answered ROBIN commented

Hey @ROBIN

You can set the label of the item on the process entry trigger using the following code.

{
Object involved = item;
string labelname = "Type";
Variant value = duniform(4,6,getstream(current));
involved.color = Color.fromPalette(value);
involved.labels.assert(labelname).value = value;
}

1742886452477.png

And also by giving the following code at Output region in processor properties. I just converted the port by case to flexScript.

Object item = param(1);
Object current = ownerobject(c);
Variant value = item.Type;
if (value == 4) {
    return 1;
}
if (value == 5) {
    return 2;
}
if (value == 6) {
    return 3;
}
return 1;

Port by Case.fsm


1742886452477.png (23.9 KiB)
port-by-case.fsm (27.2 KiB)
· 12
5 |100000

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

Felix Möhlmann avatar image Felix Möhlmann commented ·

You could also create a global table with a column for the old label value the new label value and the port through which items of that type should exit. Then use the Table().getValueByKey method in a Set Label trigger option and the Send to Port field to update the label and choose the port.

2 Likes 2 ·
ROBIN avatar image ROBIN commented ·

Hello,


Thank you for your answer.

That's just a part of what I asked for, as I said I have to do everything by flexscript, so I don't have access to the options on the picture. I have to set the function of sendtoport and the trigger.

For send to port I figured I can do it using SetProperty
"processor.setProperty("SendToPort", sendToPortCode);"

But I don't know how to set a trigger by code.

0 Likes 0 ·
ROBIN avatar image ROBIN ROBIN commented ·

I have another question please !

Let's say that I put an On process entry trigger on my processor to change the label of the item, and set the sendtoport depending on the label of the item. Would flexsim consider the first label of the item or the second ?

0 Likes 0 ·
ROBIN avatar image ROBIN ROBIN commented ·

To be more clear :

1742920544276.png

For example, the Machine MC14_1 processes three types of items. I need from MC14_1, to send the item type 57 to the stock but before change the label to 72, and then the stock would send it back to the machine.

Then I want MC14_1 to send the item type 72 after processing it and changing its label value to 438 to the first available of the machines (MC15_1, MC15_2).

0 Likes 0 ·
1742920544276.png (23.0 KiB)
Show more comments