Configure Sample Definition
The Sample Definition page on the window SPC_03_Scripting/01_Configuration has only one component:
- Button (Ignition)

Configure Button
- Drag an Ignition Button component onto the middle of the window. Resize it enough to fit the text shown above.
- Change the Text property to "Generate Sample Definition".
- Paste the following script into the Button's actionPerformed event handler script area:
Example Script to Generate a Sample Definition
Code |
interval_name = 'Every Value Change'
definition_name = 'Scripted'
attribute_name = 'attributeName'
location_path = 'New Enterprise\New Site\New Area\New Line\New Location'
rule_name = 'c Nelson Rule 1'
limit_name = 'c LCL'
# enterprise = system.mes.loadMESObjectByEquipmentPath('New Enterprise')
# interval_prop = enterprise.getComplexProperty('Interval', interval_name)
# if interval_prop is None:
# raise Exception(interval_name + ' not found')
# interval_uuid = interval_prop.getPropertyUUID()
# rule_prop = enterprise.getComplexProperty('Rule', rule_name)
# if rule_prop is None:
# raise Exception(rule_name + ' not found')
# rule_uuid = rule_prop.getPropertyUUID()
# limit_prop = enterprise.getComplexProperty('ControlLimit', limit_name)
# if limit_prop is None:
# raise Exception(limit_name + ' not found')
# limit_uuid = limit_prop.getPropertyUUID()
samp_def = system.mes.createMESObject('SampleDefinition')
samp_def.setName(definition_name)
# samp_def.setIntervalUUID(interval_uuid)
samp_def.setInterval(interval_name) # NEW!!
samp_def.setDefaultSampleSize(1) # defaults to 1
samp_def.setComingDueMinutes(0.0) # defaults to 0.0
samp_def.setOverdueMinutes(0.0) # defaults to 0.0
samp_def.setIntervalCount(0.0)
samp_def.setIntervalDuration(0.0)
samp_def.setAutoApprove(True) # defaults to false
samp_def.addRule('c Nelson Rule 1') # NEW!!
samp_def.addLimit('c LCL') # NEW!!
# samp_attr = samp_def.createComplexProperty('SampleAttribute', attribute_name)
samp_attr = samp_def.addAttribute(attribute_name)
samp_attr.setAttributeDataType('REAL') # Defaults to REAL - other options INTEGER, BOOLEAN, INSPECTED_COUNT, NONCONFORMING_COUNT, NONCONFORMITY_COUNT
samp_attr.setSampleDefaultChart('NONE') # Defaults to NONE - other options XBAR_R, XBAR_S, INDIVIDUAL, MEDIAN, U, C, P, NP, HISTOGRAM, PARETO, CP, PP, PPM, ADT, BOX_AND_WHISKER, CPPP
samp_attr.setFormat('#0.00')
samp_attr.setOrder(0) # Defaults to 0
samp_attr.setSampleSize(1) # Defaults to 1
samp_attr.setSampleDefaultValue(0) # Defaults to None
samp_attr.setSampleMinValue(0) # Defaults to None
samp_attr.setSampleMaxValue(100) # Defaults to None
samp_attr.setUnits('lbs') # Defaults to None
samp_attr.setSampleDefaultWeight(1.0) # Defaults to 1.0
# location = system.mes.loadMESObjectByEquipmentPath(location_path)
# location_uuid = location.getUUID()
# samp_loc = samp_def.createComplexProperty('SampleLocation', location_uuid)
samp_loc = samp_def.addLocation(location_path)
# samp_loc.setLocationLink(system.mes.object.link.create(location))
# samp_loc.setIntervalUUID(interval_uuid)
samp_loc.setInterval(interval_name) # NEW !!
samp_loc.setTag('Scripted') # Defaults to None
samp_loc.setComingDueMinutes(0.0) # Defaults to 0.0
samp_loc.setOverdueMinutes(0.0) # Defaults to 0.0
samp_loc.setIntervalCount(0.0) # Defaults to 0.0
samp_loc.setIntervalDuration(0.0) # Defaults to 0.0
samp_loc.setAutoApprove(True) # Defaults to False
# samp_rule = samp_def.createComplexProperty('SampleRule', rule_name)
# samp_rule.setSPCRuleUUID(rule_uuid)
# samp_limit = samp_def.createComplexProperty('SampleLimit', limit_name)
# samp_limit.setLimitKindUUID(limit_uuid)
system.mes.saveMESObject(samp_def) |