Batch size server

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
EvelineHermans
Posts: 28
Joined: Tuesday 28 July, 2015 - 10:34

Batch size server

Post by EvelineHermans »

Hello!

I'm currently struggling with the batch size (B) in a server.
I have two different products that can enter this server (red and blue) and they have to be converted from one barrel to an amount (in kgs). The red barrels consist of 75 kgs, while the blue barrels have 100 kgs. Using the Batch Rule (1 to B) I would like to convert the product from a barrel to kgs. I have defined the number of kgs per barrel in a table to make sure that I can change it easily.

But... I can't get my code for the Batch-definition working.

So far I have the following code for B:

Code: Select all

Do(
if(Label([barrel], i) = 1,Cell(1,1, refkgs_barrel)),
if(Label([barrel], i) = 2,Cell(1,2, refkgs_barrel))
)
Barrel_batch_size.mod
(12.27 KiB) Downloaded 336 times
Can someone tell me what I do wrong?

Thanks,
Eveline
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Batch size server

Post by HarryBunnik »

Ha Eveline,

You're very close. Your problems lays in the fact that when you have a red product (Label([Barrel], i) = 1) the first IF-statement is nicely returning 75. However, in the next line of code (that also will be executed) you check if the label([Barrel], i) might be 2. This returns a false and that is then the number (0) that is returned, instead of the 75 that you want (since destroying a product in a Server is not allowed, it will simply push through the main product and continue).

So the last value calculated, is what is returned and used as batchsize.

I think that if you use a case statement :

Code: Select all

Case(
  WhichIsTrue(
    Label([barrel], i) = 1,
    Label([barrel], i) = 2
  ),    
  Cell(1,1, refkgs_barrel),
  Cell(1,2, refkgs_barrel)
)
your problem would be solved.

Cheers,

Harry
Last edited by HarryBunnik on Tuesday 08 September, 2015 - 12:23, edited 1 time in total.
SimonvdW
Posts: 47
Joined: Thursday 06 January, 2011 - 09:52

Re: Batch size server

Post by SimonvdW »

Hi Eveline,

in addition: The conclusion of Harry is correct. For barrels of type 2 (blue) the second evaluation result in a 0. As a result no copy is made and just the original will move on.

An easy way of writing the Batchrule code is :

Cell(1, Label([barrel], i), refkgs_barrel)

Here the label value is used as second parameter to refer to the correct column in the table.

Regard, Simon
EvelineHermans
Posts: 28
Joined: Tuesday 28 July, 2015 - 10:34

Re: Batch size server

Post by EvelineHermans »

Thanks a lot! I now indeed see and understand where it went wrong..
Post Reply