Sepasoft MES Module Suite
system.mes.batch.recipe.syncPhasesAndSaveTemplate(mesObjectList)
Synchronizes batch phase definitions to their latest versions on one or more master recipe templates, then persists those templates. During validation, step parameters are updated from the current phase definitions, phase version markers on template logic are refreshed, and logic-level parameters are reconciled. Use this instead of saveTemplate when phases referenced by the template have changed and you need those changes applied before saving.
|
Version Specific: 3.81.10 RC3 and later |
Parameters
Parameter | Type | Required | Description |
|---|---|---|---|
mesObjectList | Required | A MESObjectList containing the BatchMasterLogic objects for the template to synchronize and save. Typically this is the list returned by loadTemplate. The list must include the full reachable template logic graph (root template logic and all related logic objects). Omitting sibling branches can cause save failures even when only one branch was edited. |
Return Value
Type | Description |
|---|---|
None | This function does not return a value. Modified objects remain in the in-memory mesObjectList passed in; reload with loadTemplate if you need a fresh copy from the database. |
Scope/Availability
Context | Available |
|---|---|
Batch Designer / client scripts (BatchClientRecipeScript) | Yes |
Gateway scripts (BatchGatewayRecipeScript) | Yes |
Both contexts invoke the same gateway logic via RPC (client) or direct handler call (gateway).
Behavior
When syncPhasesAndSaveTemplate runs, it calls the same save path as saveTemplate, but with phase synchronization enabled (updateParameters=True):
Phase parameter sync — For each step that has a phase validator, parameters on the template logic are updated from the current BatchPhase definition. Parameters marked as overridden on the template are not updated from the phase.
Phase version tracking — User-created phases (CreatorType of BATCH) have their current phase version recorded on the BatchMasterLogic. Phase versions for phases no longer used on the logic are removed.
Logic parameter sync — Logic-level parameters are updated to match the expected structure for the logic type.
Validation — The template is validated (structure, steps, unit class phase references, expressions, and so on). Validation messages are collected; Template Valid on the root logic is set to true only when there are no validation messages.
Template version — If the template already exists and has pending changes, the template version may be incremented.
Persist — All objects in mesObjectList are saved. Use system.mes.batch.recipe.saveTemplate instead of system.mes.saveMESObject() for templates.
Built-in (system) phases do not participate in phase version tracking because their versions do not change.
Excluded / Edge Cases
Overridden step parameters — Parameters with override enabled on the template are not synchronized from the phase.
Incomplete object list — Saving without the full template logic graph can fail; always pass the complete list from loadTemplate (or an equivalent fully populated list).
Template unit class — The unit class on an existing root template cannot be changed after the first save; attempting to do so raises an error.
Invalid template — The template may still be saved when validation fails; check Template Valid on the root BatchMasterLogic after the call.
Example Usage
For more examples, see: Example Scripts for Managing Templates.
Minimal example
Python |
templateLink = system.mes.batch.recipe.getTemplateLink('My Operation Template') templateList = system.mes.batch.recipe.loadTemplate(templateLink) system.mes.batch.recipe.syncPhasesAndSaveTemplate(templateList) |
Complex example
After updating a batch phase in the Phase Manager, sync every template that references it by name.
Python |
phaseLink = system.mes.batch.phase.getPhaseLink('Weigh Materials') templateClassLink = system.mes.batch.recipe.getRootTemplateLink() # Find templates under the root (adjust paging as needed) templateLinks = system.mes.batch.recipe.getTemplateLinkList( templateClassLink, 0, 2147483647, '' ) for link in templateLinks: if link.getMESObjectType() != 'BatchMasterLogic': continue templateList = system.mes.batch.recipe.loadTemplate(link) # Optional: inspect root logic before sync rootLogic = templateList.findByUUID(link.getMESObjectUUID()) if rootLogic is None: continue system.mes.batch.recipe.syncPhasesAndSaveTemplate(templateList) if not rootLogic.getTemplateValid(): system.util.getLogger('batch').warn( 'Template %s saved but is not valid after phase sync' % rootLogic.getName() ) |
Related Functions
saveTemplate() — Saves template logic without synchronizing phase parameters or phase versions (unless a step has no saved phase version yet).
syncPhasesAndSaveRecipe() — Same synchronization behavior for master recipes and associated recipe logic instead of templates.
loadTemplate() — Loads a template and all associated BatchMasterLogic objects into a MESObjectList for editing or saving.
getTemplateLink() — Resolves a template by name for use with loadTemplate.
createTemplate() — Creates a new unsaved template; use saveTemplate or syncPhasesAndSaveTemplate after configuration.
Sepasoft MES Module Suite