Overview
Custom calculations can be defined in the Misc. section of the MES Scripts under SPC Calculations. SPC module allows you to execute your miscellaneous calculations through scripting.
Applies To and Version Info
This feature applies to the SPC 3.0 module.
Steps
- Select MES Scripts in your Project Browser - this is available in the project you designate as your MES Gateway project.
- Create a new Calculation by right-clicking the table in the Misc. section and adding a script. Scripts can be added to folders for organization.

3. Name the calculation to your choosing.
4. In this example, we will create a custom Anderson-Darling Test (ADT). Set the Script type to Anderson-Darling Test (Adt).
5. Add your own script to the script window. It is suggested to use existing scripts as a template or starting point to your own scripts.
Details
The corresponding Miscellaneous Calculations Event is created for each calculation. Refer Event Objects for more details on how to use this event.
Info
|
Custom calculations can also be done using the tag change scripts where MiscCalcEvent will execute the calculation using system.mes.spc.analysis.executeMiscCalculation |

Scripting
This example calculates the CPK and PPK using the default Cppp calculation included with the module.

Example 1
This example calculates CPK and PPK via the Cppp misc calculation event.
Code |
locationPath = 'Enterprise\\El Dorado Hills\\Packaging Area\\Packaging Line 1\\Inspection Station 1'
filters = 'FromDate=2022-11-26 09:00:00|ToDate=2022-11-28 23:30:00|Location=' + locationPath
definitionName = 'Nonconformity'
attribute = 'Color'
controlLimits = 'CpPp LSL,CpPp USL'
settings = system.mes.spc.analysis.createSettings(definitionName, attribute, filters, controlLimits, '', 'Process Capability and Performance')
result = system.mes.spc.analysis.executeMiscCalculation(settings, 'Cppp')
print result.getValue('PpStdDev')
print result.getValue('CpStdDev')
print result.getValue('Ppk')
print result.getValue('Cpk')
|
Example 2
This example calculates the ADT (Anderson Darling Test).
Code |
locationPath = 'Enterprise\\El Dorado Hills\\Packaging Area\\Packaging Line 1\\Inspection Station 1'
filters = 'FromDate=2022-11-26 09:00:00|ToDate=2022-11-28 23:30:00|Location=' + locationPath
definitionName = 'Nonconformity'
attribute = 'Color'
settings = system.mes.spc.analysis.createSettings(definitionName, attribute, filters, '', '', 'Anderson-Darling Test')
result = system.mes.spc.analysis.executeMiscCalculation(settings, 'Adt')
print 'Mean: ', result.getValue('Mean')
print 'StdDev: ', result.getValue('StdDev')
print 'S: ', result.getValue('S')
print 'Ad: ', result.getValue('Ad')
print 'AdStar: ', result.getValue('AdStar')
print 'PValue: ', result.getValue('PValue')
if result.getValue('PValue') > 0.05:
print 'Since the p-value is large (>0.05), we accept the null hypotheses that the data are from a normal distribution.'
else:
print 'Since the p-value is low (<=0.05), we reject the null hypotheses that the data are from a normal distribution' |
Example 3
This example calculates the Cp (Process Capability).
Code |
locationPath = 'Enterprise\\El Dorado Hills\\Packaging Area\\Packaging Line 1\\Inspection Station 1'
filters = 'FromDate=2022-11-26 09:00:00|ToDate=2022-11-28 23:30:00|Location=' + locationPath
definitionName = 'Nonconformity'
attribute = 'Color'
controlLimits = 'Cp LSL,Cp USL,Cp Target'
settings = system.mes.spc.analysis.createSettings(definitionName, attribute, filters, controlLimits, '', 'Process Capability')
result = system.mes.spc.analysis.executeMiscCalculation(settings, 'Cp')
print result.getValue('Cp') |
Example 4
This example calculates the Control limit (Individual) using the default Control limit calculation.
Code |
locationPath = 'Enterprise\\El Dorado Hills\\Packaging Area\\Packaging Line 1\\Inspection Station 1' definitionName = 'Single Attribute' sampleDefObj = system.mes.loadMESObject(definitionName, 'SampleDefinition') attribute = 'Diameter' limitName = 'Individual LCL' toDate = system.date.now() fromDate = system.date.addHours(toDate, -2) results = system.mes.spc.controllimit.calcControlLimitValue(sampleDefObj, locationPath, attribute, limitName, fromDate, toDate) print results['calculatedValue'] |