---
title: "OEE | Scheduling OEE Production Runs by Material via Scripting"
id: "scheduling-oee-production-runs-by-material-through-scripting-3-0"
project: "Knowledge Base"
url: "https://docs.sepasoft.com/articles/knowledge-base/scheduling-oee-production-runs-by-material-through-scripting-3-0"
updated: 2026-07-23T18:08:16Z
---

# OEE \| Scheduling OEE Production Runs by Material via Scripting

### Schedule Production Runs via Scripting

## 

Example Scripts for scheduling production runs based on material information or work orders.

#### Scheduling with existing Work Orders

```python
####User edit
woName = 'WO123'
eqPath = 'JR Brews\EDH\Packaging\Packaging Line 1'
newStartDate = system.date.addHours(system.date.now(),2)
quantity = 1000
####End user edit

woObj = system.mes.workorder.getMESWorkOrder(woName)
matObj = system.mes.loadMESObject(woObj.getMaterialRefUUID())

#all oee operations are structured as materialname-enterprise:site:area:line
searchPattern = matObj.getName() + '-*' + eqPath.replace('\',':')

#https://help.sepasoft.com/docs/display/SEPA/system.mes.getAvailableOperations
results = system.mes.getAvailableOperations(eqPath,searchPattern, False, True)

if results.size() == 1:
	opDef = results.get(0).getMESObject()
	allowOverlapping = False
	category = 'Active'
	schedule = system.mes.createSchedule(opDef)
	
	#https://help.sepasoft.com/docs/display/MHD/system.mes.scheduleOperations
	scheduleList = system.mes.scheduleOperations(schedule, newStartDate, allowOverlapping, category)
	
	for ndx in range(scheduleList.size()):
	    scheduleOperations = scheduleList.get(ndx)
	    objTypeName = scheduleOperations.getMESObjectType().getName()
	    
	    ##Set the schedule production count on the Operations Schedule object (top level)
	    if objTypeName == 'OperationsSchedule':
	    	#https://help.sepasoft.com/docs/display/SEPA/Operations+Schedule
	        scheduleOperations.setScheduleProductionCount(quantity)
	                  
	    ##Set the Material Qty on the Production Request Segment
	    elif objTypeName == 'RequestSegment' and (scheduleOperations.getComplexPropertyCount('ResponseMaterial') > 0):
	    	#https://help.sepasoft.com/docs/display/SEPA/Request+Segment
	        if scheduleOperations.getAvailableMaterialOptions('Material Out').size() > 0:
	            scheduleOperations.setMaterial('Material Out', matObj.getName(), eqPath, quantity)
	#save all objects
	system.mes.saveSchedule(scheduleList)
```

#### Scheduling without Work Orders

```python
def scheduleMatRun(matName, line, startDate, startTime, qty):
	lineObj = system.mes.loadMESObject(line, 'Line')
	eqPath = lineObj.getEquipmentPath()
	matList = system.mes.oee.getEquipmentAvailableMaterial(eqPath, matName)
	matLink = matList.get(0)
	searchString = matName + '-' + eqPath.replace('\', ':')
	opList = system.mes.getAvailableOperations(eqPath, searchString, True, True)
	opDef = opList.get(0).getMESObject()
	
	schedule = system.mes.createSchedule(opDef)
	
	startDate = startDate.split('-')
	startTime = startTime.split(':')
	startDate = system.date.getDate(int(startDate[0]), int(startDate[1])-1, int(startDate[2]))       
	startDate = system.date.setTime(startDate, int(startTime[0]), int(startTime[1]), int(startTime[2])) 
	dueDate = system.date.addDays(startDate, 5)           
	scheduleList = system.mes.scheduleOperations(schedule, startDate, dueDate, True, 'Active')
 
	for ndx in range(scheduleList.size()):
		scheduleOperations = scheduleList.get(ndx)
		print scheduleOperations
		objTypeName = scheduleOperations.getMESObjectType().getName()
	     
		##Sort the schedule items in the list by their object type.
		##Set the schedule production count on the Operations Schedule object (top level)
		if objTypeName == 'OperationsSchedule':
			scheduleOperations.setScheduleProductionCount(qty)
	     	         
	    ##Set the Material Qty on the Production Request Segment
		elif objTypeName == 'RequestSegment' and (scheduleOperations.getComplexPropertyCount('ResponseMaterial') > 0):
			if scheduleOperations.getAvailableMaterialOptions('Material Out').size() > 0:
				scheduleOperations.setMaterial('Material Out', matName, eqPath, qty)
				print 'set work order scheduled qty', scheduleOperations
	
	system.mes.saveSchedule(scheduleList)
	
scheduleMatRun('PC_01', 'Line 1', '2017-05-24', '17:02:01', 150)	 
```

Result

OperationsSchedule (a09bc3ae-afbe-4b52-899a-b146355d6d71, PC\_01-Enterprise:Site 1:Area 1:Line 1 Schedule, 0 parents, 0 children, 0 custom properties, 1 complex properties)
OperationsRequest (4e1d973e-66aa-4221-bdc2-6a2a255b86cd, PC\_01-Enterprise:Site 1:Area 1:Line 1, 0 parents, 0 children, 0 custom properties, 2 complex properties)
RequestSegment (b57531c6-03ae-4152-9a7f-637c5b161ca2, PC\_01-Enterprise:Site 1:Area 1:Line 1\_CO, 0 parents, 0 children, 0 custom properties, 7 complex properties)
RequestSegment (6f505601-8dc4-4b81-822f-904628bb3a43, PC\_01-Enterprise:Site 1:Area 1:Line 1, 0 parents, 0 children, 0 custom properties, 7 complex properties)
set work order scheduled qty RequestSegment (6f505601-8dc4-4b81-822f-904628bb3a43, PC\_01-Enterprise:Site 1:Area 1:Line 1, 0 parents, 0 children, 0 custom properties, 7 complex properties)