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

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.

 

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 = 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

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