Creating and Configuring the Recipe Framework in Script

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.

Note

Reference Information, not required for this example:

Warning 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:

Once that is done, go to the next lesson to execute a batch via script.

Next