Setting Changeover Duration Based on Previous and Next Scheduled Product 3.0

There may be the need to evaluate and change the changeover duration for an operation based on what product was previously ran and what is up next in the schedule.

MES Object events are a method to intercept and modify objects during their lifecycle.

For this example, we will intercept and use two objects:

  1. Response Segment ends, extract the last ran material and save to a tag
  2. Request Segment begins from a schedule, read the last ran material for the line and set the changeover duration. 


  1. In the Response Segment Before End MES Object Event Script, paste the following script:

Code
obj = event.getMESObject()
	if '_CO' not in obj.getName():
		currentEndingMaterial = obj.getMaterialProperty('Material Out').getMaterialRef().getName()
		eqPath = obj.getEquipmentProperty().getEquipmentRefPath()

		tag = {
			"name": 'LastRunProduct',         
			"dataType": 'String',
			"value":currentEndingMaterial
		}
		tagPath = '[default]' + eqPath.replace('\\','/')
		system.tag.configure(tagPath, tag, "o")

	else:
		pass
	event.runDefaultHandler()


When a production run ends, this will create a tag in a folder structure matching your equipment path. The tag LastRunProduct will have a value of the Material Def last ran on that line.



2. In the Request Segment Schedule MES Object Event Script, paste the following script:


Code
	requestSegment = event.getMESObject()
	if '_CO' in requestSegment.getName():
		eqPath = equipmentMESObject.getMESObject().getEquipmentPath()
		tagPath = '[default]' + eqPath.replace('\\','/') + '/LastRunProduct'

		if system.tag.exists(tagPath):
			prevMaterial = system.tag.readBlocking([tagPath],1000)[0].value
			currMaterial =  requestSegment.getName().split('-')[0]
		
			#add logic here to determine changeover duration (seconds)
			CODuration = 10
			
			requestSegment.getPrimaryEndTrigger().setFixedDuration(CODuration)
			requestSegment.save()
	
	event.runDefaultHandler()



On schedule creation, this will auto evaluate the last run product and update the changeover duration based on custom logic introduced.

The Schedule View Component will reflect the setting that was saved:


It will also accommodate if schedule ordering changed since creation.


*Note - current script does not support if Material Definitions have a '-' (dash) character in the name.