Sepasoft MES Module Suite
system.mes.batch.queue.addEntry(...)
Adds a new batch to the batch queue for later execution. You pass a Batch Master Recipe or Batch Formula link plus a unique batch ID; the gateway resolves the target process cell, builds the control recipe (including optional unit assignments and batch parameters), and returns a BatchQueueEntry. In Enterprise deployments, the request is routed to the gateway that owns the equipment for the resolved process cell.
For enterprise, see Enterprise Batch Queue Management.
Syntax
Python |
system.mes.batch.queue.addEntry( masterRecipeOrFormulaLink=recipeOrFormulaLink, batchID="UNIQUE_BATCH_ID" ) system.mes.batch.queue.addEntry( masterRecipeOrFormulaLink=recipeLink, batchName="Display Name", batchID="UNIQUE_BATCH_ID", priority=10, scale=1.0, quantity=100.0, unitAssignments={"Unit Procedure 1": "Enterprise\\Site\\Area\\Process Cell\\Unit 1"}, batchParameters={"Param1": 10, "Param2": True}, processCellPath="Enterprise\\Site\\Area\\Process Cell" ) |
Parameters
Required
Parameter | Type | Required | Description | ||
|---|---|---|---|---|---|
masterRecipeOrFormulaLink | MESObjectLink | Required | Link to a Batch Master Recipe or Batch Formula to execute. Must not be None. If you use a formula link, the formula must be valid and its recipe user version must match the master recipe.
| ||
batchID | String | Required | Unique identifier for this batch. Cannot be blank. Must not match any batch currently in the queue or any batch already executed (historical use of the ID is rejected). |
Optional
Parameter | Type | Required | Default | Description | ||
|---|---|---|---|---|---|---|
batchName | String | Optional | Master recipe name | Human-readable batch name. Multiple queue entries may share the same name. If omitted or blank, the master recipe name is used.
| ||
priority | Integer | Optional | 50 | Used for reference and by the allocation manager. Lower values mean higher priority (product documentation describes 1 as highest priority). If omitted, the runtime applies the default priority constant (50). | ||
scale | Double | Optional | 1.0 | Optional scale factor for recipe calculations. | ||
quantity | Double | Optional | 1.0 | Batch size; used in recipe calculations and by the allocation manager (e.g., unit capacity checks). | ||
unitAssignments | PyDictionary | Optional | None | Maps sub-logic step names (unit procedure steps in the master recipe) to unit equipment: each value is either a String equipment path or an MESObjectLink to a MESUnit. Keys must match step names that exist with sublogic on the recipe; values must not be None. Ex: {'Unit Procedure 1':'Enterprise\Site\Area\Process Cell\Unit A'} | ||
batchParameters | PyDictionary | Optional | None | Parameter name → value pairs applied to the procedure logic after the control recipe is created. Values must be Serializable types suitable for batch parameters. | ||
processCellPath | String | Optional | (resolved) | Equipment path to the target MES Process Cell. Use when defining batches from an Enterprise context so the path aligns with where the recipe syncs. If omitted, the process cell is inferred from unitAssignments, the master recipe’s associated equipment, or (on a server with exactly one process cell) that cell. | ||
masterRecipeLink | MESObjectLink | Optional | — | Deprecated. Use masterRecipeOrFormulaLink instead. Still accepted as a fallback when masterRecipeOrFormulaLink is not supplied. |
Returns
The new queue entry object for the created batch (control recipe built, parameters applied, execution state initialized). Use it with other system.mes.batch.queue.* functions (for example getEntry, executeEntryCommand, removeEntry). |
Scope / Availability
Registered on the system.mes.batch.queue script module (Sepasoft Batch / MES).
Gateway: Runs on the gateway; the entry is appended to the local runtime queue when the process cell’s equipment is hosted on that server.
Designer / Client: Same API; calls go to the connected gateway via RPC. Enterprise routing: the gateway forwards addQueueEntry to the server closest to the resolved process cell’s equipment path when that owner is not the local gateway.
Excluded / Edge Cases
Link type — masterRecipeOrFormulaLink (or deprecated masterRecipeLink) must be a Batch Master Recipe or Batch Formula link; otherwise an IllegalArgumentException is raised.
Blank batch ID — Raises Exception: "The batch id cannot be blank."
Duplicate batch ID — Raises if the ID is already in the queue or was used by a completed/archived batch ("already in the queue" / "has already been used").
Invalid or out-of-sync formula — Formula must be valid and match the master recipe user version; otherwise creation fails with a descriptive Exception.
Master recipe not validated — If the resolved master recipe has not been successfully validated, addQueueEntry fails with an error naming the recipe.
Process cell resolution — If the process cell cannot be determined (e.g., multiple cells and no disambiguating path/assignments), Exception is raised with guidance to supply processCellPath, unitAssignments, or use a single-cell server configuration.
processCellPath — Must resolve to a MES Process Cell equipment object; otherwise Exception ("is not a Process Cell").
Recipe vs. process cell — The master recipe’s unit class assignments must be consistent with the chosen process cell; cross–process cell mismatches raise Exception (wording differs for local vs. sync scenarios).
Unit assignments — Values must be String paths or MESObjectLink to MESUnit; None values per key are rejected. Assigned units must belong to the same process cell as the resolved target when a cell is already fixed.
MES runtime and license — The MES system must be started and the Batch module must be licensed; otherwise gateway checks fail before the entry is created.
Local queue list — The in-memory queue on a gateway only receives the entry when equipment for that process cell is on that server; remote routing still completes addQueueEntry on the owning gateway.
Example Usage
Minimal Example
Python |
# recipeLink is an MESObjectLink to a Batch Master Recipe entry = system.mes.batch.queue.addEntry( masterRecipeOrFormulaLink=recipeLink, batchID="BATCH-2026-0001" ) |
Complex Example
Python |
recipeLink = system.mes.batch.recipe.getRecipeLink(name="MyMasterRecipe") entry = system.mes.batch.queue.addEntry( masterRecipeOrFormulaLink=recipeLink, batchName="Spring Production Run", batchID="BATCH-2026-0002", priority=5, scale=1.0, quantity=500.0, processCellPath="Enterprise\\Site1\\AreaA\\Mixer Cell", unitAssignments={ "Charge": "Enterprise\\Site1\\AreaA\\Mixer Cell\\Mixer 1" }, batchParameters={ "TargetTemp": 72.5, "UseAdditive": True } ) system.mes.batch.queue.executeEntryCommand( entry, system.mes.batch.queue.COMMAND_START() ) |
Related Functions
system.mes.batch.queue.addOrUpdateEntry(entry) — Adds or updates an existing BatchQueueEntry (editable fields) instead of creating from a fresh request.
system.mes.batch.queue.getEntry(batchID) — Retrieves a queue entry by batch ID.
system.mes.batch.queue.getEntries(pageNumber, pageSize, searchPattern) — Lists queue entries with paging and wildcard search.
system.mes.batch.queue.executeEntryCommand(batchQueueEntry, command) / executeEntryCommandAsync — Sends batch commands (e.g. COMMAND_START()) to a queue entry.
system.mes.batch.queue.assignUnit(batchQueueEntry, unitProcedurePath, unitEquipmentPath) — Assigns a unit to a unit procedure on an existing entry.
system.mes.batch.queue.removeEntry(batchQueueEntry) — Removes an entry from the queue.
system.mes.batch.queue.changeEntryPriority(batchQueueEntry, newPriority) — Updates priority after the entry exists.
Using the addEntry Scripting Function
These scripting examples detail how to programmatically create and manage batch entries within a Manufacturing Execution System (MES), a critical capability for modern production environments. The strategic importance of this function lies in its ability to automate production scheduling and enable seamless integration with external systems, such as an Enterprise Resource Planning (ERP) platform. By leveraging this function, organizations can achieve centralized control over distributed manufacturing operations, ensuring data consistency and process integrity. To effectively use this function, it is essential to first understand the foundational equipment model concepts that inform the function's parameters.
Foundational Concepts: The ISA88 Equipment Model
A clear understanding of the physical equipment model is essential for correctly targeting batch operations. The MES Batch Procedure module is designed to be compliant with the ISA88 standard, providing a structured and hierarchical representation of production assets. This model ensures that scripts can reliably and unambiguously direct batch jobs to the correct physical equipment on the plant floor.
Process Cell
A Process Cell is a logical grouping that represents all the physical equipment required for a complete production line. This can encompass various manufacturing types, including continuous processes, converting lines, discrete manufacturing, or packaging lines. It serves as the primary container for a set of related production activities.
Unit
A Unit represents a specific piece of equipment where a batch control operation is executed. During batch execution-time, there is a strict one-to-one relationship between a Unit Procedure (a step in a recipe) and a physical Unit. A Unit is allocated to a Unit Procedure when the Unit Procedure step becomes active in the recipe, linking the procedural logic to the physical asset that will perform the work.
Equipment Hierarchy
The equipment model follows a clear hierarchical path structure, which is used to uniquely identify any asset within the enterprise. This path is fundamental for targeting batch operations correctly.
Enterprise > Site > Area > Process Cell > Unit
With these core concepts established, we can now examine the detailed syntax and parameters of the system.mes.batch.queue.addEntry() function itself.Function Deep Dive: system.mes.batch.queue.addEntry()
The system.mes.batch.queue.addEntry() function is the primary scripting command for creating new batch entries in the MES queue. It provides a powerful interface for automating the initiation of production runs with precise control over recipe selection, quantity, and equipment allocation. This section deconstructs its syntax and defines its most critical parameters.
Function:
system.mes.batch.queue.addEntry(masterRecipeLink, batchName, batchID, priority, scale, quantity, unitAssignments, batchParameters, processCellPath)
Key Parameter Definitions for these examples:
masterRecipeLink: The link to the master recipe that this batch will execute.
batchName: The unique name for the batch entry.
batchID: The unique identifier for the batch entry.
priority: The priority of the batch in the queue.
scale: The scale for the batch execution.
quantity: The quantity for the batch execution.
unitAssignments: A dictionary used to explicitly allocate a specific Equipment Unit to a procedure within the recipe (e.g., {'P2': unitPath}).
processCellPath: The explicit equipment path to the Process Cell that should run the batch.
The system uses these parameters to construct and place the batch job. The processCellPath, in particular, is a key argument that directly influences the system's logic for determining where the batch should be executed, as detailed in the following section.Core Operational Logic and Process Cell Targeting
The system employs a sophisticated logic to determine the correct Process Cell for a new batch entry. This logic is crucial for ensuring that batches are executed on the intended equipment, especially in a distributed environment with multiple sites or production lines. The behavior is primarily driven by the processCellPath parameter and the context from which the function is called.
Conditional Behavior (from Enterprise Level)
When the system.mes.batch.queue.addEntry() function is called from the Enterprise level, its behavior changes based on whether the processCellPath is provided.
When processCellPath IS provided:
The Batch Queue Entry is created directly on the target Site gateway. It is then synchronized up to the Enterprise for centralized visibility.
When processCellPath IS NOT provided:
Scenario 1: If the Enterprise itself has a configured Process Cell, the system assumes the Enterprise can execute the batch. The entry is created at the Enterprise level and will not sync down to a Site.
Scenario 2: If the Enterprise does not have its own Process Cell, the entry automatically syncs down to the Site that is capable of executing the associated recipe.
The four targeting methods detailed below are the mechanisms the system uses to determine the Process Cell, which in turn dictates which of the conditional Enterprise-level synchronization behaviors is triggered.
Methods for Targeting a Process Cell
There are four primary methods the system can use to identify the target Process Cell for a new batch:
Direct Specification: Providing the explicit equipment path in the processCellPath argument. This is the most direct and unambiguous method.
Unit Derivation: Deriving the Process Cell from the parent of a Unit specified in the unitAssignments argument.
Automatic (Single Cell): In a simple configuration with only one Process Cell, the system will automatically select it without requiring an explicit path.
Unit Class Derivation: Deriving the Process Cell from the parent of a Unit that is assigned to the Unit Class specified within the recipe's Unit Procedure.
The following section provides practical code examples to demonstrate how this logic is applied in common implementation scenarios.
Practical Implementation: Code Examples
This section presents three practical, scripted examples that demonstrate how to add batch queue entries in different common scenarios. These examples range from a simple, single-cell setup to more complex configurations involving explicit equipment allocation, illustrating the flexibility of the system.mes.batch.queue.addEntry() function.
Example 1: Implicit Process Cell in a Single-Cell Environment
Scenario: In a simple site-level configuration with only one Process Cell, the processCellPath parameter is not required. The system can automatically infer and assign the batch to the correct queue. This automatic assignment is based on the Unit Procedure configuration within the batch recipe, where a Unit Class is selected, which in turn links to the site's available Equipment Units.Python |
#Getting required params and objects bid = 'batch123' recipeClassName = 'Test' recipeName = 'ConsumeMaterialLot' recClassLink = system.mes.getMESObjectLinkByName('BatchMasterRecipeClass', recipeClassName) masterRecipeLink = system.mes.batch.recipe.getRecipeLink(recipeName, recClassLink) system.mes.batch.queue.addEntry(masterRecipeLink=masterRecipeLink, batchName=bid, batchID=bid, priority=1.0, scale=1.0, quantity=1.0) |
Example 2: Explicitly Specifying the Process Cell
Scenario: In an environment with multiple Process Cells, it is best practice to explicitly direct the batch to the correct production equipment. This script uses the processCellPath argument to remove any ambiguity.Python |
#Getting required params and objects bid = 'batch123' recipeClassName = 'Test' recipeName = 'ConsumeMaterialLot' recClassLink = system.mes.getMESObjectLinkByName('BatchMasterRecipeClass', recipeClassName) masterRecipeLink = system.mes.batch.recipe.getRecipeLink(recipeName, recClassLink) processCellPath = 'New Enterprise\New Site\New Area\New Process Cell' system.mes.batch.queue.addEntry(masterRecipeLink=masterRecipeLink, batchName=bid, batchID=bid, priority=1, scale=1.0, quantity=1.0, processCellPath=processCellPath) |
Outcome Analysis: The explicit processCellPath argument ensures the batch is added to the batch queue of the specified "New Process Cell". This method is essential for reliable scheduling in complex manufacturing environments.
Example 3: Specifying Process Cell and Equipment Allocation
Scenario: This advanced example demonstrates how to not only target a Process Cell but also pre-assign a specific Equipment Unit (Unit 5) to a procedure within the batch recipe (identified by the name 'P2').
Code:
Python |
#Getting required params and objects bid = 'batch123' recipeClassName = 'Test' recipeName = 'ConsumeMaterialLot' recClassLink = system.mes.getMESObjectLinkByName('BatchMasterRecipeClass', recipeClassName) masterRecipeLink = system.mes.batch.recipe.getRecipeLink(recipeName, recClassLink) unitPath = 'New Enterprise\New Site\New Area\New Process Cell\Unit 5' system.mes.batch.queue.addEntry(masterRecipeLink=masterRecipeLink, batchName=bid, batchID=bid, priority=1, scale=1.0, quantity=1.0, unitAssignments={'P2':unitPath}) |
Outcome Analysis: The unitAssignments dictionary forces the allocation of Unit 5 to the P2 procedure for this specific batch run. This provides granular control over equipment usage. The Process Cell is derived using the "Unit Derivation" method described previously, as the system identifies the parent of the explicitly assigned Unit 5.
These practical examples transition from the "how-to" of scripting to the broader strategic context of using these functions within an enterprise architecture.
System Design Philosophy
A fundamental design principle of this architecture is the prioritization of data correctness over system availability. In practice, this means batch operations are designed to fail if network connectivity to a remote site is down. This intentional behavior prevents data discrepancies that could arise from operating on stale information, guaranteeing that all decisions are based on the most current and accurate state of the system.
ERP Order Update Workflow
A common application of enterprise-level batch operations is handling order modifications from an external system like an ERP. The following workflow demonstrates how to use the full suite of batch commands to ensure data integrity when an order is updated.
Receive Change Notification: The Enterprise gateway receives a notification from the ERP system that an existing production order has been modified.
Verify Batch Status: Before making changes, the system checks if the corresponding batch has already started by calling system.mes.batch.queue.getStatus(batchID).
Remove Existing Batch (If Inactive): If the status check confirms the batch has not yet started, the old, outdated batch entry is deleted by calling system.mes.batch.queue.removeEntry().
Create New Batch with Updated Data: Finally, a new batch entry is created with the updated information from the ERP by calling system.mes.batch.queue.addEntry().
This deliberate workflow, born from the system's design philosophy, is further governed by a set of strict operational rules essential for maintaining system integrity.
Important Considerations and System Limitations
To build robust and predictable workflows, it is crucial to understand the system's operational rules and limitations. Adhering to these constraints will prevent unexpected errors and ensure system integrity.
Command Execution Restrictions
There is an absolute rule governing command execution: The Enterprise is explicitly forbidden from executing commands on a Site child Batch. To "reset" a batch, users must call the system.mes.batch.queue.removeEntry() function. Attempting to execute other commands from the Enterprise to modify a batch's state will fail.
Understanding Race Conditions
A potential race condition can occur during a multi-step batch update process. For example, if a user fetches batch information, modifies it locally, then deletes the old batch to add the new one, another user could modify the batch on the remote system between the read and delete operations. This could lead to inconsistent data.
However, this is not a concern under the following two conditions:
The new batch being created is not based on the data from the old one.
The system enforces a policy where batches are immutable and are never written to after their initial creation.
Adherence to these guidelines and a clear understanding of the function's operational logic are crucial for implementing successful and reliable batch automation solutions.
Sepasoft MES Module Suite