SPC:SCR: Configure Sample Collection

Configure Sample Collection

The Sample Collection page on the window SPC_03_Scripting/02_Production Control has four main components:

  1. Three Numeric Text Field (Ignition)
  2. Button (Ignition)


Configure Labels and Numeric Text Fields

  • Drag three Label components onto the window. Position and resize as shown above.

  • Drag three Ignition Numeric Text Field components onto the window. Position under each Label and resize as shown.

  • Change each LabelText property:
    1. Top Label: Diameter
    2. Middle Label: Location X
    3. Bottom Label : Location Y

  • Change each Name property:
    1. Top Numeric Text Field: ntf_diameter
    2. Middle Numeric Text Field: ntf_locationX
    3. Bottom Numeric Text Field: ntf_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
    {Root Container.ntf_diameter.intValue} !=0 &&
    {Root Container.ntf_locationX.intValue} !=0 &&
    {Root Container.ntf_locationY.intValue} !=0
  • Open the Component Scripting dialog box (Ctrl-J), select the actionPerformed event handler script area and paste in the script below:

Script for actionPerformed event handler

Code
diameter = event.source.parent.getComponent('ntf_diameter').intValue
locationX = event.source.parent.getComponent('ntf_locationX').intValue
locationY = event.source.parent.getComponent('ntf_locationY').intValue

eqPath = 'New Enterprise\\Site\\Area\\Line 1\\Sample Location'


##Older Method supported in 2.0 
##(and supported in 3.0 for backwards compatibility):
#sample = system.quality.sample.data.getNewByDefName('Dimension Sample B', eqPath)
#sample.setSampleData(1, 'Diameter', str(diameter))
#sample.setSampleData(1, 'LocationX', str(locationX))
#sample.setSampleData(1, 'LocationY', str(locationY))
##sample.setNote('Some Note')
##sample.setProductCode('Some Product Code')
##sample.setRefNo('Some Reference Number')
##sample.addAddlFactor(factorName, factorValue, recordDateTime)
#system.quality.sample.data.updateSample(eqPath, sample, 1)


##Newer Method supported in 3.0:
dataDict = {'Diameter':diameter,'LocationX':locationX,'LocationY':locationY}
system.mes.spc.sample.collect('Dimension Sample B', eqPath, dataDict, sampleTakenDateTime=system.date.now()) 

system.gui.messageBox('Sample Collected', 'Sample Collected')
diameter = event.source.parent.getComponent('ntf_diameter').intValue = 0
locationX = event.source.parent.getComponent('ntf_locationX').intValue = 0
locationY = event.source.parent.getComponent('ntf_locationY').intValue = 0