The SPC module provides methods to create samples through scripting without using any visual components.
Applies To and Version Info
This feature applies to the SPC module and is available in all versions.
1. Create a sample definition:
- Create a sample definition called 'XBarTest' and assigned the location 'QCLab1'. The definition is set for a maximum of 5 measurements max per attribute.
- It has two attributes, Attr1 and Attr2:
- Attr1 is real type and is set for 1 measurement
- Attr2 is real type and is set for 4 measurements
2. Create a new sample from the definition.
3. Add sample data to the attributes and their measurements.
4. Update/save the sample object.
The following code performs steps 2, 3 and 4:
# sample definition name
defName = 'XBarTest'
# location path that is assigned to the sample definition
locationPath = '[global]\Nuts Unlimited\Folsom\Packaging\QCLab1'
# create a new sample from the definition
sample = system.quality.sample.data.getNewByDefName(defName, locationPath) #https://help.sepasoft.com/docs/display/MHD/system.quality.sample.data.getNewByDefName
# use this sample object to set the data for the attributes and their measurements
# this sample definition has two attributes, Attr1 and Attr2, and Attr1 has 1 measurement and Attr2 has 4 measurements
# read the values from existing tags
# NOTE: sample values are passed as strings, they are converted internally to the proper data type.
att1Val = system.tag.read('Quality/QualVal1').value
sample.setSampleData(1, 'Attr1', str(att1Val))
att2Val = system.tag.read('Quality/QualVal2').value
sample.setSampleData(1, 'Attr2', str(att2Val))
att3Val = system.tag.read('Quality/QualVal3').value
sample.setSampleData(2, 'Attr2', str(att3Val))
att4Val = system.tag.read('Quality/QualVal4').value
sample.setSampleData(3, 'Attr2', str(att4Val))
att5Val = system.tag.read('Quality/QualVal5').value
sample.setSampleData(4, 'Attr2', str(att5Val))
# only approved samples display on the chart
# save the sample by calling it's update method
system.quality.sample.data.updateSample(locationPath, sample, True) # https://help.sepasoft.com/docs/display/MHD/system.quality.sample.data.updateSample
Get Sample By Definition Name
SPC, Sample Definition, Sample Attribute