Product: MoveProduct
There are variants of MoveProduct depending upon the target and the parameters passed.
Attempting to place Product on equipment other than a ProductSchedule, another product or a Rack produces the message:
"Destination is not a Transporter, Product Schedule, Product container nor Rack"
1) Move product to Transporter or Product Schedule
Called to move product from one transporter to another. Requires 3 parameters.
Function
Object MoveProduct(product: Product, target: string, distance: number);
Parameters
Name | Type | Description |
---|---|---|
product | Product | The object to move. If move to product schedule, this can be a new product object created by ‘CreateProduct’ and a product will be created in the Product Schedule. |
target | String | The name of the destination transporter or product schedule. If this is an empty string the product is moved to ‘limbo’, it will have no parent and will not be visible within the simulation. When moved to a product schedule, the product.Scheduler property will be set to the product schedule it moved to. If product.Scheduler is NULL then it means it failed to move. (ie exceeded max queue size) |
distance | Number | The distance along the transfer path of the transporter that the product will be inserted |
Return Value
Void (or the schedule object, if moved to a Product Schedule)
Example
MoveProduct(childProduct, parentProduct.Name, 0); // Place of top, centre of parentProduct
Remarks
Products are moved to transports by being removed from their current transport (if any) and added to the destination transport. This is true even if the current transport is the same as the destination transport. In particular, this means that any subscribed OnProductAdded events will be called. Beware of this pattern:
function OnSimulationStart() {
SubscribeToEvent("OnProductAdded", "Conveyor1", "Conveyor", RepositionProductIncorrectly);
}
function RepositionProductIncorrectly(conveyor, product) {
// This will call the RepositionProductIncorrectly until an error is generated!
MoveProduct(product, conveyor.Name, 0.5);
}
If a product is added to Conveyor1, the OnProductAdded handler RepositionProductIncorrectly
will be called. The MoveProduct
call, despite only intending to move the product slightly, will cause the product to be removed and readded to Conveyor1…which calls the OnProductAdded handler RepositionProductIncorrectly
, which calls MoveProduct
, which calls RepositionProductIncorrectly
.
If you want to reposition a product inside an OnProductAdded handler, your event handler will need to discern between the initial call and the subsequent calls generated by MoveProduct
. This can be as simple as a boolean flag that you set when moving a product, and clear once the movement is complete. The important thing is that whatever method you choose, it must persist between function calls:
function OnSimulationStart() {
SubscribeToEvent("OnProductAdded", "Conveyor1", "Conveyor", RepositionProduct);
}
function RepositionProduct(conveyor, product) {
// Construct a counter that keeps its value between calls.
if (RepositionProduct.recursionCounter === undefined) {
// This block is only entered the first time this function is called.
RepositionProduct.recursionCounter = 0;
}
// If we're not in the middle of a MoveProduct call, call MoveProduct.
if (RepositionProduct.recursionCounter === 0) {
++RepositionProduct.recursionCounter;
try {
MoveProduct(product, conveyor.Name, 0.5);
} finally {
// Wrap the decrement in a finally in case MoveProduct throws.
--RepositionProduct.recursionCounter;
}
}
}
2) Move product to a Rack
Called to move product into the cell of a Rack. Requires 4 parameters.
Function
void MoveProduct(
product: Product,
target: string,
indexX: integer,
indexY: integer);
void MoveProduct(
product: Product,
target: string,
indexX: integer,
indexY: integer,
offsetX: double,
offsetY: double,
offsetZ: double,
direction: double,
tilt: double,
roll: double);
Parameters
Name | Type | Description |
---|---|---|
product | Product | The object to move. If move to product schedule, this can be a new product object created by ‘CreateProduct’ and a product will be created in the Product Schedule. |
target | String | The name of the destination Rack. |
indexX | integer | The column cell (zero based) to place Product into |
indexY | integer | The row cell (zero based) to place Product into |
offsetX | double | OPTIONAL: X position of product inside the cell. Default = 0.0 and is center of cell |
offsetY | double | OPTIONAL: Y position of product inside the cell. Default = 0.0 and is center of cell |
offsetZ | double | OPTIONAL: Z position of product inside the cell. Default = 0.0 and is center of cell |
direction | double | Direction (in degree) of product inside the cell. Default = 0.0 |
tilt | double | Tilt (in degree) of product inside the cell. Default = 0.0 |
roll | double | Roll (in degree) of product inside the cell. Default = 0.0 |
Return Value
None
Example
MoveProduct(childProduct, rack.Name, 2, 1); // Place in grid 2,1 of the specified Rack
3) Move Product to a Product container
Called to move product to a Product container or another Product. Requires 3 to 8 parameters.
A Product container can be a Product or an Array of products.
When moving a Product on a Product, unless specified the ‘child’ product will be displayed on top , in the centre of the ‘parent’ product. New parameters allow this to be controlled.
Function
void MoveProduct(product: Product, target: string, X: double, Y: double, Z: double, direction: double, tilt: double, roll: double);
Parameters
Name | Type | Description |
---|---|---|
product | Product | The object to move. If move to product schedule, this can be a new product object created by ‘CreateProduct’ and a product will be created in the Product Schedule. |
target | String | The name of the product container or parent Product. |
X | double | The X position to place the Product at |
Y | double | The Y position to place the Product at |
Z | double | The Z position to place the Product at |
direction | double | The direction in degrees for the Product |
tilt | double | The tilt in degrees for the Product |
roll | double | The roll in degrees for the Product |
Return Value
None
Example
MoveProduct(childProduct, products[cells[1]].Name, -0.15, 0.20, 0.10); // Place at X,Y,Z coordinates on array of Product
MoveProduct(childProduct, parentProduct.Name, 1.0, -21.0, 0.0, 45, 30, 20); // Place at X,Y,Z coordinates on Parent Product specifying a Direction, Tilt and Roll