Special Variables

These are special Python variables that can be used in specific areas of GainSeeker.

See Python commands for other commands you can use with GainSeeker.

 

Contents  [Hide]

 

List of Special Variables

Variable

Applies to

Description

New or changed in GainSeeker version

cancelrequested

PC Collect inspection

In a Formula test with the FormulaMode property set to ClickToggle, when the inspector clicks the Formula button a second time to finish running the script, this variable will be set to True and the current script will complete execution but not automatically run again.

This is a global variable.

Your Python script can use a while loop that executes some code while this variable is False and exits the script when this variable is True. This is especially useful if you need to perform some setup steps such as opening a port or connecting to a device, which you may only want to execute once (for better performance).

9.3

cancelsubmit

PC Collect inspection

This variable can be set to one of these values:

  • False (the default value) : When the user clicks Submit, data records for the sub-inspection are stored in the GainSeeker database and the sub-inspection data entry window is closed.

  • True : When the user clicks Submit, the sub-inspection data entry window remains open and data records for the sub-inspection are not stored in the GainSeeker database. The sub-inspection cannot be submitted until this variable is set to False .

You can set this variable in any script in the sub-inspection.

Each time a sub-inspection is opened, this variable is reset to False .

 

newstat

Custom statistics

Set this variable equal to the final desired value of the custom statistic you are creating or editing.

 

result

Device Profile

Set this variable equal to the final desired value of the measurement being entered.

You can also set this variable to an asterisk ( * ) in place of a missing measurement. For more information, see Entering an incomplete subgroup.

If the inspector clicks Cancel while waiting for a reading from the Device Profile, this variable will be set to None.

9.3

testid

PC Collect inspection

The testid variable identifies which activity triggered the execution of a Python script.

Python script triggered by:

testid =

InspectionScript Inspection property

"[INSPECTION_SCRIPT]"

Formula test with FormulaMode property = Pre

"[PRE]"

Formula test with FormulaMode property = Post

"[POST]"

Formula test with FormulaMode property = Click

the TestID property of the Formula test button that was clicked

Formula test with FormulaMode property = ClickToggle

the TestID property of the Formula test button that was clicked

Formula test with FormulaMode property = OnChange

the TestID property of the test whose value changed

Formula test with FormulaMode property = Cancel

"[CANCEL]"

Clicking the message area button

"[MESSAGEAREA]"

8.8, 9.1, 9.2, 9.3

Example

For the above scenario, you could use the following code in a Formula test (where the FormulaMode property is set to Post):

if inspect.cursubi.passfail(1).value == 1 and inspect.cursubi.trace(2).value == "" :

disp.message("Please complete the required traceability.")  #This reminds the operator to complete the traceability.

cancelsubmit = True  #This will prevent the operator from submitting the sub-inspection.

else:

cancelsubmit = False  #This will allow the operator to submit the sub-inspection.

Using a Function or Class to set a Special Variable

Keep in mind that all Special Variables are global variables. This means that if you want to use a Python function to set one of these variables, you must either declare that variable as global within your function, or use the main script to set the value of the variable based on a value returned by the function or an attribute of a class object.

 

For example, these two scripts DO NOT WORK because they fail to set the global variable:

 

Example 1:

def updateCancelSubmit():

# since we are assigning a value to cancelsubmit in the local scope of this function,

# Python assumes we want a local variable.

# this local variable will not affect the global cancelsubmit variable

cancelsubmit = True

 

updateCancelSubmit()

 

# will print False because the value of the global cancelsubmit variable remains unchanged

print cancelsubmit

 

Example 2:

def updateCancelSubmit(cancelsubmit):

# in this example we are passing in the VALUE of the global cancelsubmit variable,

# but this is still a local variable and changing the value will not affect the global cancelsubmit variable

cancelsubmit = True

 

updateCancelSubmit(cancelsubmit)

 

# will print False because the value of the global cancelsubmit variable remains unchanged

print cancelsubmit

 

Here are some examples that would CORRECTLY set a special variable:

Declaring the variable as 'global' (inside the function)

def myfunction() :

global cancelsubmit #declares that we mean the global variable 'cancelsubmit'

if some_condition_is_met :

cancelsubmit = True

 

myfunction()

Setting the variable based on a function return value

def myfunction() :

myvar = False

if some_condition_is_met :

myvar = True

return myvar #calling myfunction() will return the value of this myvar variable

 

cancelsubmit = myfunction() #because we are setting this outside of the function, it is automatically treated as a global variable

Setting the variable based on an attribute of a class object

class myclass() :

myvar = False

def myfunction(self):

self.myvar = True

 

mything = myclass() #creates a new 'mything' object based on the class 'myclass'

mything.myfunction() #calls the 'myfunction' method on the 'mything' object

cancelsubmit = mything.myvar #because we are setting this outside of the function, it is automatically treated as a global variable