---
title: "SPC:Perspective:Script:Configure Sample Collection"
id: "spc-perspective-script-configure-sample-collection"
project: "Tutorials"
url: "https://docs.sepasoft.com/articles/mes-module-tutorials/spc-perspective-script-configure-sample-collection"
updated: 2026-07-23T18:14:00Z
---

# SPC:Perspective:Script:Configure Sample Collection

## Configure Sample Collection

Create a new view **SPC\_03\_Scripting/Production Control**

The production control screen demonstrates how to manually collect samples (not triggered by the SPC module). The script function [system.mes.spc.sample.collect](/smart/project-imported-manual/system-mes-spc-sample-collect-defname-locationpath-attributedata-factordata-takenby-note-approved-r) can be used in tag change scripts, timer scripts, or other event based mechanisms providing maximum flexibility for SPC sampling.
 
This screen is comprised of 3 main components:

1. Three - [Numeric Entry Field](https://www.docs.inductiveautomation.com/docs/8.1/appendix/components/perspective-components/perspective-input-palette/perspective-numeric-entry-field?utm_term=&amp;utm_campaign=002+Ignition+Performance+Max&amp;utm_source=adwords&amp;utm_medium=ppc&amp;hsa_acc=1942977828&amp;hsa_cam=19829025962&amp;hsa_grp=&amp;hsa_ad=&amp;hsa_src=x&amp;hsa_tgt=&amp;hsa_kw=&amp;hsa_mt=&amp;hsa_net=adwords&amp;hsa_ver=3&amp;gad_source=1&amp;gad_campaignid=21210041500&amp;gbraid=0AAAAAD-80zj9wj8Glu9sL3sQQaNHVj8h0&amp;gclid=CjwKCAjwtfvEBhAmEiwA-DsKjvDKgNqeMbZ4A8a0E1XbDrIOfV2X2GB_Kh-NlPCGmF5iCmUWCo7JeBoCkEEQAvD_BwE) Each will input an attribute data.

2. [Button](https://www.docs.inductiveautomation.com/docs/8.1/appendix/components/perspective-components/perspective-input-palette/perspective-button) - for sample collection

3.[MES Object Selector](/smart/project-imported-manual/mes-object-selector-perspective) - with includeMESLocationObjects = true

![](/resources/Storage/mes-module-tutorials/spc-perspective-script-configure-sample-collection/spc-perspective-script-configure-sample-collection-2025-08-15-3.png)

### Configure Labels and Numeric Text Fields

* Drag three **Label** components onto the window. Position and resize as shown above.
* Drag three Ignition **Numeric Entry Field** components onto the window. Position under each **Label** and resize as shown.
* Change each **Label** **Text** property:
    1. Top Label: ***Diameter***
    2. Middle Label: ***Location X***
    3. Bottom Label : ***Location Y***
* Change each **Name** property:
    1. Top Numeric Text Field: ***nef\_diameter***
    2. Middle Numeric Text Field: ***nef\_locationX***
    3. Bottom Numeric Text Field: ***nef\_locationY***

* * *

### Configure 'Collect Sample Via Script' Button

* Drag an Ignition **Button** component onto the window. Resize it enough to fit the text shown above.
* Change the **Text** property to ***Collect Sample Via Script***.
* Bind the **Enabled** property with the following expression:

    Expression for Enabled property

Code

```
{../nef_diameter.props.value} != '' &&
{../nef_locationX.props.value} != '' &&
{../nef_locationY.props.value} != ''
```

* Open the Component Scripting dialog box (Ctrl-J), select the **actionPerformed** event handler script area and paste in the script below:

Script for onActionPerformed event handler

Code

```
def runAction(self, event):
	diameter = self.getSibling("nef_diameter").props.value
	locationX = self.getSibling("nef_locationX").props.value
	locationY = self.getSibling("nef_locationY").props.value
	
	locationPath = self.getSibling("mesObjectSelector").props.selectedMESObject.equipmentPath
	
	dataDict = {'Diameter':diameter,'LocationX':locationX,'LocationY':locationY}
	system.mes.spc.sample.collect('Dimension Sample B', locationPath, dataDict)
	
	#reset:
	self.getSibling("nef_diameter").props.value = ''
	self.getSibling("nef_locationX").props.value = ''
	self.getSibling("nef_locationY").props.value = ''
```

Button enabled expression binding:

![](/resources/Storage/mes-module-tutorials/spc-perspective-script-configure-sample-collection/spc-perspective-script-configure-sample-collection-2025-08-15-2.png)

Button event handler:

![](/resources/Storage/mes-module-tutorials/spc-perspective-script-configure-sample-collection/spc-perspective-script-configure-sample-collection-2025-08-15-1.png)

[Next](/articles/mes-module-tutorials/spc-perspective-script-configure-analysis-data)