Creating a Batch Recipe Structure via Script
These code examples have been functionalized.
Functionalizing enables saving in the Scripts folder in the Project Browser and calling the function where needed.
|
Reference Information, not required for this example:
|
|
If you are using the starter project and want to leverage the automation scripts for batches, name all equipment exactly as given. |
Create a Set of Unit Functionality via Script
Python |
phaseClassName = 'Demo' parentPhaseClass = None unitClassName = 'Premix' parentUnitClassName = 'Demo' phaseName = 'Value Prompt' recipeClassName = 'Training' parentRecipeClassName = None def createPhaseClass(phaseClassName, parentPhaseClass): phaseClass = system.mes.batch.phase.createClass(phaseClassName, None) phaseClass.save() def createUnitClass(unitClassName, parentUnitClassName): # check if unitClassParentName is None, then set the parent link to None if parentUnitClassName == None: parentUnitClassLink = None else: parentUnitClassLink = system.mes.batch.unitclass.getLink(parentUnitClassName) # if not None, then get the parent link unitClass = system.mes.batch.unitclass.create(unitClassName, parentUnitClassLink) unitClass.save() def addPhaseToUnitClass(unitClassName, phaseName): # get the unit class unitClassLink = system.mes.batch.unitclass.getLink(unitClassName) unitClass = unitClassLink.getMESObject() # get the phase phaseLink = system.mes.batch.phase.getPhaseLink(phaseName) # add the phase to the unit class unitClass.addPhase(phaseLink) # save unitClass.save() def associateUnitClassToUnit(unitName, unitClassName): # get the unit unitLink = system.mes.batch.unit.getLink(unitName) # get the unit class unitClassLink = system.mes.batch.unitclass.getLink(unitClassName) # associate the unit to the unit class system.mes.batch.unit.assignUnitClass(unitLink, unitClassLink) def createRecipeClass(recipeClassName, parentRecipeClassName): # check if recipeClassParentName is None, then set the parent link to None if parentRecipeClassName == None: parentRecipeClassLink = None else: parentRecipeClassLink = system.mes.batch.recipe.getRecipeLink(parentRecipeClassName) # if not None, then get the parent link recipeClass = system.mes.batch.recipe.createRecipeClass(recipeClassName, parentRecipeClassLink) recipeClass.save() |
You can take the functions and save into an Ignition project library to reuse them.
Now that you have the recipe elements in place, do these things:
- Assigning a Unit Class to an equipment Unit
- Create the Basic Kitchen Timer Recipe by hand assigning the Unit Procedure to the Unit Class: Premix. The Unit Class assignment is not part of that basic recipe so remember to do this after completing this scripting example.
Once that is done, go to the next lesson to execute a batch via script.