---
title: "Automate Sample Collection with Timed interval - another condition is met 3.0"
id: "automate-sample-collection-with-timed-interval-another-condition-is-met-3-0"
project: "Knowledge Base"
url: "https://docs.sepasoft.com/articles/knowledge-base/automate-sample-collection-with-timed-interval-another-condition-is-met-3-0"
updated: 2026-07-23T18:08:24Z
---

# Automate Sample Collection with Timed interval \- another condition is met 3\.0

## Overview

Implementation of SPC interval that will check for an additional condition before taking the sample. This example will show how to check if the line is running when using a location under a line.

### Applies To and Version Info

This feature applies to the SPC module and is available in all 3.8x versions.

### Example Model

![](/resources/Storage/knowledge-base/automate-sample-collection-with-timed-interval-another-condition-is-met-3-0/image2022-12-28_14-52-16.png)

### Steps

Create a custom Sample interval using the MES Scripts in the Project Browser

![](/resources/Storage/knowledge-base/automate-sample-collection-with-timed-interval-another-condition-is-met-3-0/image2022-12-28_14-49-28.png)

![](/resources/Storage/knowledge-base/automate-sample-collection-with-timed-interval-another-condition-is-met-3-0/image2022-12-28_16-20-20.png)

Use one of the standard timed intervals as a framework for your script.

Your Line should have [Live Analysis](/articles/user-manual/Live-Analysis) configured with the Equipment Mode Type data point enabled.

In this example, we read from the Equipment Mode Type tag for the parent line to determine if the Line is in Production. If so, create a sample.

![](/resources/Storage/knowledge-base/automate-sample-collection-with-timed-interval-another-condition-is-met-3-0/image2022-12-28_16-19-5.png)

Example Interval Script

Code

```
from java.util import Calendar
secSinceLastSample = event.getSecSinceLastSampleScheduled()

#Calculate the interval in seconds
intervalSec = event.getInterval() * 60 
comingDueSeconds = event.getComingDueMin() * 60

#If a sample has not been scheduled or intervalSec has expired, schedule a new sample
if secSinceLastSample == None or secSinceLastSample >= intervalSec - comingDueSeconds:
	
	locationPath = event.getLocationPath()
	
	#check if line is running
	locationObj = system.mes.loadMESObjectByEquipmentPath(locationPath)
	line = locationObj.getParentCollection().getList().get(0).getMESObject()
	laPath = '[MES]' + line.getEquipmentPath().replace('\','/')  + '/Live Analysis/Current Shift/Equipment Mode Type'
	
	if system.tag.readBlocking([laPath],1000)[0].value == 'Production':
		cal = Calendar.getInstance()
		cal.add(Calendar.SECOND, int(comingDueSeconds))
		event.setScheduleStart(cal.getTime())
		
		#Create new sample
		event.setCreateSample(1)


```


Ref: [Sample Interval Event](/articles/user-manual/Sample-Interval-Event)

On the Enterprise Equipment, Edit PC Sample Intervals. Create a new interval and select your new script. In this example, the script is a Timed interval.

![](/resources/Storage/knowledge-base/automate-sample-collection-with-timed-interval-another-condition-is-met-3-0/image2022-12-28_15-1-21.png)

Your [Sample Definition Location](/articles/user-manual/Sample-Definition-Location) should have the new Custom interval selected.

![](/resources/Storage/knowledge-base/automate-sample-collection-with-timed-interval-another-condition-is-met-3-0/image2022-12-28_15-8-33.png)

Loggers can be added to the Interval script to ensure you are receiving the data you expected.

## Keywords

SPC Interval

/docs/pages/viewpage.action?pageId=786923