Create Material Production Settings via Script 3.0

Step-by-step guide

  • The Material Definition (Material Class - Material Name) will be created if they do not exist.
  • Line path must exist.
  • Infeed/Outfeed equipment must be either the Line Path or children of the Line. More on the production model: Production Equipment Model
Python
#creates material and material class if does not already exist
def configureMaterial(matName, matClass):
import time
try:
matClassObj = system.mes.loadMESObject(matClass, 'MaterialClass')
except:
root = system.mes.loadMESObject('Material Root','MaterialRoot')
matClassObj = system.mes.createMESObject('MaterialClass')
matClassObj.setName(matClass)
matClassObj.addParent(root)
print 'creating material class',matClass
matDefObj = system.mes.createMESObject('MaterialDef')
matDefObj.setName(matName)
matDefObj.addParent(matClassObj)
list = system.mes.object.list.createList()
list.add(matClassObj)
list.add(matDefObj)
system.mes.saveMESObjects(list)
print 'creating material definition',matName
time.sleep(1)

def configMaterialOperation(matName, matClassName, config):
try:
matLink = system.mes.getMESObjectLinkByName('MaterialDef', matName)

except:
configureMaterial(matName, matClassName)
matLink = system.mes.getMESObjectLinkByName('MaterialDef', matName)

operList = system.mes.oee.createMaterialProcessSegment(matLink, config['linePath'])
for opSeg in operList:
#Set Operations Def progress tracking
if opSeg.getMESObjectTypeName() == 'OperationsDefinition':
print opSeg.getTrackProgressBy()
if config.has_key('trackProductionBy') and config['trackProductionBy'] == 'time':
opSeg.setTrackProgressBy('Use Time')
else:
opSeg.setTrackProgressBy('Material Out')
if opSeg.getMESObjectTypeName() == 'OperationsSegment':
#set up production settings
if '_CO' not in opSeg.getName():
matProp = opSeg.getComplexProperty('Material', 'Material Out')
if matProp:
if config.has_key('scheduleRate'):
matProp.setRate(float(config['scheduleRate']))
if config.has_key('infeedUnits'):
matProp.setUnits(config['infeedUnits'])
if config.has_key('ratePeriod'):
matProp.setRatePeriod(config['ratePeriod'])
#sets only line settings
productionSettings = opSeg.getComplexProperty('ProductionSettings', 0)
if config.has_key('OEERate'):
productionSettings.setOEERate(float(config['OEERate']))
if config.has_key('outfeedUnits'):
productionSettings.setOutfeedUnits(config['outfeedUnits'])
if config.has_key('infeedUnits'):
productionSettings.setInfeedUnits(config['infeedUnits'])
if config.has_key('rejectUnits'):
productionSettings.setRejectUnits(config['rejectUnits'])
if config.has_key('outfeedEquipmentPath'):
outfeedEquipLink = system.mes.getMESObjectLinkByEquipmentPath(config['outfeedEquipmentPath'])
productionSettings.setOutfeedEquipmentRef(outfeedEquipLink)
if config.has_key('infeedEquipmentPath'):
infeedEquipLink = system.mes.getMESObjectLinkByEquipmentPath(config['infeedEquipmentPath'])
productionSettings.setInfeedEquipmentRef(infeedEquipLink)
if config.has_key('packageCount'):
productionSettings.setPackageCount(float(config['packageCount']))
opSeg.setPropertyValue('ProductionSettings', productionSettings)
triggerEnd = opSeg.getPrimaryEndTrigger()
if config.has_key('autoEndProduction'):
triggerEnd.setAuto(config['autoEndProduction'] == 'True')
if config.has_key('trackProductionBy'):
if config['trackProductionBy'] == 'time':
triggerEnd.setMode('Schedule (time)')
else:
triggerEnd.setMode('Schedule (production)')
else:
#Set Changeover end settings
triggerEnd = opSeg.getPrimaryEndTrigger()
if config.has_key('autoEndChangeover'):
triggerEnd.setAuto(config['autoEndChangeover'] == 'True')
if config.has_key('changeoverDuration'):
triggerEnd.setFixedDuration(int(config['changeoverDuration']))
try:
system.mes.saveMESObjects(operList)
return True
except:
return False


materialDefName = 'test03'
materialClass = 'TestClass1'
config = {
"materialName":materialDefName,
"materialClass":materialClass,
"productionSettings":{
"linePath": "Enterprise\\El Dorado Hills\\Packaging Area\\Packaging Line 3",
"infeedEquipmentPath": "Enterprise\\El Dorado Hills\\Packaging Area\\Packaging Line 3\\Depal",
"outfeedEquipmentPath": "Enterprise\\El Dorado Hills\\Packaging Area\\Packaging Line 3\\Palletizer",
"OEERate":"101",
"scheduleRate":"80",
"ratePeriod": "Min",
"infeedUnits":"cans",
"outfeedUnits": "cases",
"rejectUnits": "cans",
"autoEndChangeover":"True",
"autoEndProduction":"True",
"changeoverDuration":"65",
"packageCount":"1",
"trackProductionBy":"time"
}
}
#create material production settings
configMaterialOperation(config['materialName'], config['materialClass'], config['productionSettings'])
#Get all Settings for given material
matClassLink = system.mes.getMESObjectLinkByName('MaterialDef', materialDefName)
opsegs = system.mes.oee.getMaterialOperationsSegments(matClassLink, '*')
lineProdSettings = []
import pprint
for opSeg in opsegs:
if '_CO' not in opSeg.getName():
matProp = opSeg.getComplexProperty('Material', 'Material Out')
print opSeg
if matProp:
lineSetting = {
'linePath':opSeg.getEquipment().getEquipmentPath(),
'ratePeriod': matProp.getRatePeriod(),
'infeedUnits': matProp.getUnits(),
'scheduleRate': matProp.getRate()
}
#returns only the line settings
productionSettings = opSeg.getComplexProperty('ProductionSettings', 0)
lineSetting.update({"OEERate":productionSettings.getOEERate()})
lineSetting.update({"outfeedUnits":productionSettings.getOutfeedUnits()})
if productionSettings.getOutfeedEquipmentRef():
lineSetting.update({"outfeedEquipmentPath":productionSettings.getOutfeedEquipmentRef().getMESObject().getEquipmentPath()})
else:
lineSetting.update({"outfeedEquipmentPath":None})
if productionSettings.getInfeedEquipmentRef():
lineSetting.update({"infeedEquipmentPath": productionSettings.getInfeedEquipmentRef().getMESObject().getEquipmentPath()})
else:
lineSetting.update({"infeedEquipmentPath":None})
lineSetting.update({"packageCount": productionSettings.getPackageCount()})
triggerEnd = opSeg.getPrimaryEndTrigger()
if triggerEnd:
lineSetting.update({"trackProductionBy":triggerEnd.getMode()})
lineSetting.update({"autoEndProduction":triggerEnd.isAuto()})
else:
triggerEnd = opSeg.getPrimaryEndTrigger()
lineSetting.update({'autoEndChangeover':triggerEnd.isAuto()})
lineSetting.update({'changeoverDuration':triggerEnd.getFixedDuration()})
lineProdSettings.append(lineSetting)
pprint.pprint(lineProdSettings)

Example Output:

Replace items in config dictionary to adjust Production Settings to your needs


Read more about Material Production settings here: OEE Material Production Settings