Create Recipe with Add-Begin-End

Sepasoft MES Module Suite

Creating a Batch Recipe with Parallel Processing

Python
def dirObj(obj,searchString):
	allMembers = dir(obj)
	for member in allMembers:
		if searchString in member:
			print(member)

def createRecipe(recipeClassName, recipeName):
	# Get Recipe Class
	recipeClass = system.mes.batch.recipe.loadRecipeClass(recipeClassName, None)
	try:
		# Get Recipe
		recipeLink = system.mes.batch.recipe.getRecipeLink(recipeName, recipeClass.asLink())
		
		# Remove Recipe
		system.mes.batch.recipe.removeRecipe(recipeLink)
	except:
		pass
		
	#Create the BatchMasterRecipe
	recipe = system.mes.batch.recipe.createRecipe(recipeName, recipeClass.asLink())
	recipe.setRecipeState('Production Ready')
	recipe.setRecipeScale(1.0)
	recipe.setQuantity(1.0)
	recipe.setUserVersion(1)
	sl = saveList.add(recipe)
	
	#Create a BatchMasterLogic object for the main procedure. 
	#This is the object that holds all of the tasks
	procedure = recipe.createLogic(recipeName)
	sl = saveList.add(procedure)
	
	#Add a Start
	st = procedure.addStep("Start", 0, system.mes.batch.phase.getBuiltInPhaseLink('Start'))
	
	p1 = procedure.addParameter('UDP_Parameter_A')
	p1.setParamDataTypeName('Boolean')
	p1.setParamValueSourceName('Recipe and Execution')
	#p1.setParamKindName('User Logic')
	p1.setParamRecordingTypeName('All to Object and History')
	p1.setParamValue(True)
	
	return procedure
	
def finishCreatingRecipe(procedure):
	#Add the terminator for the recipe.
	stepNum = procedure.getComplexPropertyCount('BatchMasterLogicSteps')
	end = procedure.addStep('End', stepNum, system.mes.batch.phase.getBuiltInPhaseLink('Terminator'))
	l = procedure.addLink(stepNum-1,stepNum)
	
def add_Timer10(procedure, priorStepNum, addTransition):
	#Add phase to the procedure
	stepNum = procedure.getComplexPropertyCount('BatchMasterLogicSteps')
	stepName = 'P'+str(stepNum)
	procedure_phase = procedure.addStep(stepName, stepNum, system.mes.batch.phase.getPhaseLink('Timer 10'))
	l = procedure.addLink(priorStepNum,stepNum)
	
	if addTransition == True:
		#Add a transition
		priorStepName = stepName
		stepNum = procedure.getComplexPropertyCount('BatchMasterLogicSteps')
		stepName = 'P'+str(stepNum)
		procedure_Transition = procedure.addStep(stepName, stepNum, system.mes.batch.phase.getBuiltInPhaseLink('Transition'))
		procedure_Transition.setParameterValueAsString('Transition_Expression', priorStepName+'.Complete', True)
		#Add the link to the transition
		l = procedure.addLink(stepNum-1,stepNum)

def addUP_Timer10(procedure, priorStepNum, addTransition):
	#Create the unit procedure
	unitClass_link = system.mes.loadMESObject('Mixer','BatchUnitClass').asLink()
	unitProcedure = procedure.createLogic('UP_Timer10')
	sl = saveList.add(unitProcedure)
	unitClassRef = unitProcedure.setUnitClassRef(unitClass_link)
	
	#Add the start to the unit procedure
	unitProcedure_Start = system.mes.batch.phase.getBuiltInPhaseLink("Start")
	unitProcedure_Start_step = unitProcedure.addStep("UP1", 0, unitProcedure_Start)
	
	#Add phase to the unit procedure
	unitProcedure_phase = unitProcedure.addStep("UP2", 1, system.mes.batch.phase.getPhaseLink('Timer 10'))
	#Add the link from the Start to the phase
	l = unitProcedure.addLink(0,1)
	
	#Add a transition after the phase
	unitProcedure_Transition = unitProcedure.addStep('UP3', 2, system.mes.batch.phase.getBuiltInPhaseLink('Transition'))
	unitProcedure_Transition.setParameterValueAsString('Transition_Expression', 'UP2.Complete', True)
	#unitProcedure_Transition.setParameterValueAsString('Transition_Expression', '/{}.' + workCenterID + '_Release', True)
	l = unitProcedure.addLink(1,2)	
	
	#Add an End phase
	unitProcedure_Transition = unitProcedure.addStep('UP4', 3, system.mes.batch.phase.getBuiltInPhaseLink('Terminator'))
	l = unitProcedure.addLink(2,3)
	
	param = unitProcedure.addParameter('RandomString')
	param.setParamDataTypeName('String')		
	param.setParamValueSourceName('Recipe and Execution')
	param.setParamRecordingTypeName('All to Object and History')
	param.setParamValue('This is a string.')
	#param.setParameterCalculation('Include_' + opKey,'param("/{}.Include_'+opKey+'")')
	
	#Add the unit procedure as a step in the recipe
	p2 = system.mes.batch.phase.getBuiltInPhaseLink("Unit Procedure")
	stepNum = procedure.getComplexPropertyCount('BatchMasterLogicSteps')
	stepName = 'P'+str(stepNum)
	s1 = procedure.addStep(stepName, stepNum, p2)
	p2_uuid = unitProcedure.getUUID()
	s1.setLogicRefUUID(p2_uuid)
	l = procedure.addLink(priorStepNum,stepNum)	
	
	if addTransition == True:
		#Add a transition after the unit procedure
		priorStepName = stepName
		stepNum = procedure.getComplexPropertyCount('BatchMasterLogicSteps')
		stepName = 'P'+str(stepNum)
		procedure_Transition = procedure.addStep(stepName, stepNum, system.mes.batch.phase.getBuiltInPhaseLink('Transition'))
		procedure_Transition.setParameterValueAsString('Transition_Expression', priorStepName+'.Complete', True)
		#Add the link from UP to the transition
		l = procedure.addLink(stepNum-1,stepNum)

#Create a list of objects to save
saveList = system.mes.object.list.createList()


recipeClassName = 'Training'
recipeName = 'Scripted'
procedure = createRecipe(recipeClassName, recipeName)

#Add AND-BEGIN
andBeginStepNum = procedure.getComplexPropertyCount('BatchMasterLogicSteps')
s=procedure.addStep('AND_BEGIN1', andBeginStepNum, system.mes.batch.phase.getBuiltInPhaseLink('And Begin'))
l = procedure.addLink(andBeginStepNum-1,andBeginStepNum)

stepNumA = procedure.getComplexPropertyCount('BatchMasterLogicSteps')
add_Timer10(procedure, andBeginStepNum, False)
stepNameA = 'P'+str(stepNumA)

stepNumB = procedure.getComplexPropertyCount('BatchMasterLogicSteps')
addUP_Timer10(procedure, andBeginStepNum, False)
stepNameB = 'P'+str(stepNumB)

#Add AND-END
stepNum = procedure.getComplexPropertyCount('BatchMasterLogicSteps')
s=procedure.addStep('AND_END1', stepNum, system.mes.batch.phase.getBuiltInPhaseLink('And End'))
l = procedure.addLink(stepNumA,stepNum)
l = procedure.addLink(stepNumB,stepNum)

#Add a transition after the And End
stepNum = procedure.getComplexPropertyCount('BatchMasterLogicSteps')
stepName = 'P'+str(stepNum)
procedure_Transition = procedure.addStep(stepName, stepNum, system.mes.batch.phase.getBuiltInPhaseLink('Transition'))
trExp = stepNameA+'.Complete AND '+stepNameB+'.Complete'
procedure_Transition.setParameterValueAsString('Transition_Expression', trExp, True)
l = procedure.addLink(stepNum-1,stepNum)

stepNum = procedure.getComplexPropertyCount('BatchMasterLogicSteps')
add_Timer10(procedure, stepNum-1, True)

stepNum = procedure.getComplexPropertyCount('BatchMasterLogicSteps')
addUP_Timer10(procedure, stepNum-1, True)

stepNum = procedure.getComplexPropertyCount('BatchMasterLogicSteps')
add_Timer10(procedure, stepNum-1, True)

stepNum = procedure.getComplexPropertyCount('BatchMasterLogicSteps')
addUP_Timer10(procedure, stepNum-1, True)

finishCreatingRecipe(procedure)

#Save the recipe
system.mes.batch.recipe.saveRecipe(saveList)



Sepasoft MES Module Suite