Sepasoft MES Module Suite
BatchFormula Object
Overview
A Batch Formula is a definition object that stores scaled material quantities and parameter overrides for a specific Batch Master Recipe. Formulas are organized under Batch Formula Class folders (or directly under the Batch Formula Root) and are used when operators queue batches from the Formula Manager or from scripts. Each formula references exactly one master recipe and tracks whether it is synchronized with the latest recipe version.
|
Persist changes with system.mes.batch.formula.saveFormula() — not system.mes.saveMESObject(). Remove formulas with system.mes.batch.formula.removeFormula(). |
|
Version Specific Available in 3.81.11 RC 1 Batch Procedure Module and later. |
Obtaining a BatchFormula
Python |
# By name under a formula class (returns MESObjectLink; call getMESObject() for the full object) classLink = system.mes.batch.formula.getFormulaClassLink('Production Formulas', None) link = system.mes.batch.formula.getFormulaLink('Standard 1000 kg', classLink) formula = link.getMESObject() # Load directly by name and parent formula = system.mes.batch.formula.loadFormula('Standard 1000 kg', classLink) # Load by link formula = system.mes.batch.formula.loadFormula(link) # Create a new unsaved formula from a master recipe recipeLink = system.mes.batch.recipe.getMasterRecipeLink('My Master Recipe', None) formula = system.mes.batch.formula.createFormula('New Formula', recipeLink, classLink) |
Object Identity
Field | Value |
|---|---|
Type name | BatchFormula |
Kind | Definition |
Required module | Batch |
Root object | BatchFormulaRoot (via system.mes.batch.formula.getRootFormulaLink()) |
Object Hierarchy
Relationship | Allowed type(s) | Notes |
|---|---|---|
Parent | BatchFormulaClass or BatchFormulaRoot | Single parent only (SINGLE_PARENT). If none is provided at create time, the root formula object is assigned automatically. |
Children | (none) | Formulas are leaf objects. Use Batch Formula Class objects to organize formulas in a folder tree. |
Formula classes (BatchFormulaClass) can nest under the root or under other classes and may contain both child classes and formulas.
Core Properties
These properties are inherited from AbstractMESObject and apply to every BatchFormula.
Property | Access | Type | Description |
|---|---|---|---|
Name | getName() / setName(name) | String | Unique among sibling formulas under the same parent class or root. |
Description | getDescription() / setDescription(description) | String | Optional description. |
UUID | getUUID() | String | Stable object identifier. |
Enabled | isEnabled() / setEnabled(value) | Boolean | Whether the object is active. Removal disables the object rather than deleting it. |
BatchFormula Properties
Property | Access | Type | Default | Description |
|---|---|---|---|---|
Master Recipe Reference | getMasterRefUUID() / setMasterRefUUID(uuid) | String | (required) | UUID of the Batch Master Recipe this formula is based on. Set automatically when the formula is created from a recipe link. |
Formula Valid | isFormulaValid() / setFormulaValid(value) | Boolean | False | Whether the formula passed validation. Updated when saved through saveFormula() or when validateFormula() runs. Invalid formulas cannot be used to queue a batch. |
State | getState() / setState(state) | String | Inactive | Lifecycle state from the Formula_State enum. Accepted values: Production Ready, Preproduction, Inactive. |
State UUID | getStateUUID() | String | (enum UUID) | Raw enum option UUID stored in the database. Prefer getState() / setState() in scripts. |
User Version | getUserVersion() / setUserVersion(version) | Integer | 1 | Formula version counter. Incremented automatically on save when the saved version is equal to or greater than the in-memory version. Reset to 1 when a formula is copied or imported. |
Recipe User Version | getRecipeUserVersion() / setRecipeUserVersion(version) | Integer | (from recipe) | User version of the master recipe the formula was last synchronized with. When this differs from the current recipe version, the formula is stale until synced. |
Scale | getScale() / setScale(scale) | Double | 1.0 | Batch scale factor applied to the formula. |
Quantity | getQuantity() / setQuantity(quantity) | Double | 1.0 | Batch quantity for the formula. |
Parameter overrides are stored as complex properties on the formula. They merge with master-recipe parameter definitions at runtime; only changed fields are persisted on the formula object.
BatchFormula Methods
Recipe and validation
Method | Return type | Description |
|---|---|---|
validateFormula() | List of String | Runs validation and returns error messages. An empty list means the formula is valid. Does not persist changes. |
isModified() | Boolean | Whether in-memory changes have not been saved. |
asLink() | MESObjectLink | Lightweight link to this formula. |
Parameter access
Parameter paths use the same friendly path format as batch recipe parameters (for example, a step-scoped path such as /MyProcedure:Charge.SugarAmount).
Method | Return type | Description |
|---|---|---|
getParameters(includeMasterRecipeParameters) | List of BatchParameter | All parameters visible on this formula. Set includeMasterRecipeParameters to True to include recipe defaults not overridden on the formula. Items returned when includeMasterRecipeParameters is True are read-only views; changes to them do not persist. |
getAllParameterProperties() | List of BatchFormulaParameterProperty | Complex property objects persisted on this formula. |
getParameterValue(paramPath) | Object | Current effective parameter value (formula override or recipe default). |
getParameterValueAsString(paramPath) | String | Parameter value formatted as a string. |
getParameterMinValue(paramPath) | Object | Effective minimum value. |
getParameterMinValueAsString(paramPath) | String | Minimum value as a string. |
hasParameterMinValue(paramPath) | Boolean | Whether a minimum value is set. |
getParameterMaxValue(paramPath) | Object | Effective maximum value. |
getParameterMaxValueAsString(paramPath) | String | Maximum value as a string. |
hasParameterMaxValue(paramPath) | Boolean | Whether a maximum value is set. |
setParameterValue(paramPath, value) | None | Override the parameter value on this formula. |
setParameterMinValue(paramPath, minValue) | None | Override the minimum value. Must remain within recipe constraints. |
setParameterMaxValue(paramPath, maxValue) | None | Override the maximum value. Must remain within recipe constraints. |
setParameterReadOnly(paramPath, readOnly) | None | Override whether the parameter is read-only in the Formula Manager. |
setParameterVisible(paramPath, visible) | None | Override whether the parameter is visible in the Formula Manager. |
setParameterSticky(paramPath, sticky) | None | Override whether the parameter value is sticky across batch runs. |
resetParameter(paramPath) | None | Remove all formula overrides for the parameter and revert to recipe defaults. |
Scope / Availability
Context | How to access |
|---|---|
Gateway scripts | system.mes.batch.formula.* and methods on loaded BatchFormula objects |
Client / Designer scripts | Same module via RPC (BatchClientFormulaScript) |
Perspective / engineering UI | Batch Formula Manager component (mes.batch.formulaManager) |
Exceptions and Constraints
Situation | Behavior |
|---|---|
Save through system.mes.saveMESObject() | Blocked: "Batch Formula must be saved through system.mes.batch.formula.saveFormula" |
Remove/disable through generic MES remove | Blocked while enabled: "Batch Formula must be removed through system.mes.batch.formula.removeFormula" |
createFormula with blank name | IllegalArgumentException: "Formula name is required" |
createFormula without a valid master recipe link | Exception: "A valid recipe link is required to base the formula from" |
createFormula with wrong link type | Exception: recipe link must reference BatchMasterRecipe |
setState(invalidState) | IllegalArgumentException: state not found on Formula_State enum |
Duplicate sibling name on save | Name is auto-adjusted to the next available sibling name |
Referenced recipe disabled or invalid at validation | UnvalidatableFormulaException with recipe-specific message |
Formula recipe version behind master recipe | Validation message: "Referenced recipe version is not the latest…" or StaleFormulaException when editing parameters on a stale formula |
Invalid formula queued for batch | Blocked at runtime — formula must be valid (isFormulaValid() is True) |
Import with duplicate UUID | Exception: UUID already taken |
Import when referenced recipe missing | IllegalArgumentException: master recipe UUID does not exist |
When calling saveFormula(formula, syncWithRecipe=True), parameter overrides that no longer exist on the latest recipe are removed, and invalid override values may be cleared automatically during validation.
Example Usage
Minimal example — load a formula and read a parameter
Python |
classLink = system.mes.batch.formula.getFormulaClassLink('Production', None) formula = system.mes.batch.formula.loadFormula('Standard Batch', classLink) print('State:', formula.getState()) print('Valid:', formula.isFormulaValid()) paramPath = '/Mixing:Charge.TargetWeight' value = formula.getParameterValueAsString(paramPath) print('Target weight:', value) |
Complex example — create, configure, validate, and save
Python |
# Resolve parent class and master recipe classLink = system.mes.batch.formula.getFormulaClassLink('R and D', None) recipeLink = system.mes.batch.recipe.getMasterRecipeLink('Pilot Recipe', None) # Create and configure the formula formula = system.mes.batch.formula.createFormula('Pilot 500 kg', recipeLink, classLink) formula.setDescription('Scaled pilot batch') formula.setScale(0.5) formula.setQuantity(500.0) formula.setState('Preproduction') # Override a recipe parameter paramPath = '/Mixing:Charge.TargetWeight' formula.setParameterValue(paramPath, 500.0) formula.setParameterVisible(paramPath, True) # Check validation before save errors = system.mes.batch.formula.validateFormula(formula) if errors: for msg in errors: print('Validation:', msg) # Persist (syncWithRecipe=False keeps existing overrides; True reconciles with latest recipe) system.mes.batch.formula.saveFormula(formula=formula, syncWithRecipe=False) # Reload to confirm saved state saved = system.mes.batch.formula.loadFormula(formula.asLink()) print('Saved formula valid:', saved.isFormulaValid()) |
Sync a stale formula after a recipe change
Python |
link = system.mes.batch.formula.getFormulaLink('Standard Batch', classLink) # Sync this formula to the latest recipe version and save system.mes.batch.formula.syncRecipeAndSaveFormula(link) # Or sync all formulas that reference a recipe after a master recipe save system.mes.batch.formula.syncAndSaveFormulasUsingRecipe(recipeLink) |
Related Functions
Module: system.mes.batch.formula
Function | Description |
|---|---|
Returns the BatchFormulaRoot link. | |
Look up a formula link by name under a formula class. | |
getFormulaLinkList(parentLink, pageNumber, pageSize, searchPattern) | Paginated list of formula and class links under a parent. |
Load a full BatchFormula object. | |
Create a new unsaved formula from a master recipe. | |
Copy an existing formula (resets user version). | |
Validate and persist a formula. Returns nothing; check formula.isFormulaValid() after reload. | |
Disable and remove a formula. | |
Return validation error messages without saving. | |
Create an unsaved formula from XML (recipe must exist). | |
Export a formula to XML. | |
Sync one formula to its recipe's latest version and save. | |
Sync all formulas linked to a master recipe. | |
getFormulaParameters(formula, includeMasterRecipeParameters) | List parameters for a formula or link. |
Read a parameter value. | |
Set a parameter value override. | |
Bulk-update parameter fields from dictionaries created with createFormulaParameterDictionary(). | |
Reset a parameter to recipe defaults. | |
Build a field dictionary for bulk parameter updates. |
Formula class CRUD (createFormulaClass, saveFormulaClass, getFormulaClassLink, loadFormulaClass, and related functions) operates on BatchFormulaClass objects in the same module.
Related Objects and Components
Related object types
BatchFormulaRoot — Single root container for all formulas and formula classes.
BatchFormulaClass — Folder object for organizing formulas.
BatchMasterRecipe — Master recipe that defines base parameters and logic referenced by a formula.
BatchControlRecipe — Runtime control recipe created when a batch is queued from a formula.
Related components
Batch Formula Manager (mes.batch.formulaManager) — Perspective component for browsing, editing, importing, exporting, and queuing batches from formulas.
Sepasoft MES Module Suite