question

hugror avatar image
1 Like"
hugror asked Jason Lightfoot commented

When 2 given items are on a pallet, combine them into another

Hi,

I have some pallets that can have 2 types of items on it. When 1 item of each type is on a pallet, I want to transform them into one other item.

For instance :

1 item1 + 0 Item2 = 1 item1

0 item1 + 1 Item2 = 1 item2

1item1 + 1 item2 = 1 item3

2items1 + 1 item2 = 1item1 + 1item3

and so on.


Is there any simple way to make the transformation ?

thanks in advance.

FlexSim 23.1.0
combinerpalletitem
· 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.

Jason Lightfoot avatar image Jason Lightfoot ♦ commented ·

Hi @hugror, was José Antonio MD's answer helpful? If so, please click the "Accept" button at the bottom of their answer. 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 comment back to reopen your question.

0 Likes 0 ·

1 Answer

·
José Antonio MD avatar image
1 Like"
José Antonio MD answered José Antonio MD commented

Hello @Hugror,

You have different options to achieve your objective: using more objects or modifiying the logic.

An easy way would be to use for example the OnProcessFinish event and customize the logic (see an example using a Trigger in the combiner: by editing the code you will be able to change labels, delete objects, create, etc.). You could also do it using ProcessFlow (although I don't know if you have some knowledge using ProcessFlow).

I hope I have helped you.

23.1. FlexSimExample.fsm


· 8
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 ·

Another option would be to modify the OnReceive code of the pallet, so the exchange of a pair of items to a new one happens "in the background" without any additional logic in the model itself.

If you want to use this option, I'd be better if you created a copy of the pallet flowitem and modified that instead of the original.

merge-on-pallet-fm.fsm

1 Like 1 ·
hugror avatar image hugror commented ·

Thanks for the answers.

Right now I have this code inside OnProcessFinish, but the probleme is that it is deleting only 1/2 items. Moreover, obj01 and obj09 seem to be equal to 0.

/**Custom Code*/
Object current = ownerobject(c);
Object item = param(1);

int obj01;
int obj09;
int tot;

for(int i=1;i<=item.subnodes.length;i++){ //Loop
/*Create your logic*/
if (item.subnodes[i].label1=="01"){
obj01=obj01+1;

}
if (item.subnodes[i].label1=="09"){
obj09=obj09+1;
}
}

tot=obj01+obj09;

if (obj01==obj09){
for(int i=1;i<=item.subnodes.length;i++)
item.subnodes[i].destroy();
}
0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann hugror commented ·
You have to decrement the loop variable when deleting the items in a for loop. Take the example of two items on the pallet. At i == 1, the first is destroyed. Now there is only one item, i increments to 2, which is larger than 1 and the loop terminates.

To delete all subnodes, using a while-loop is simpler.

while(item.subnodes.length > 0) {
    item.first.destroy();
}
I can't say why obj01 and obj09 would be 0 without seeing the model.
1 Like 1 ·
hugror avatar image hugror Felix Möhlmann commented ·

Thanks. Indeed I thought about it just after posting my comment, but even when setting i at 4 (4items on my pallet), it was deleting 1/2 items without reason. Anyway, your solution is working fine.


Here is my model. The code is inside the combiner where the sources are 1 and 4

sfpv6.fsm

0 Likes 0 ·
sfpv6.fsm (78.4 KiB)
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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