Declaration
Unlike Python variables, TPT assessment variables must be declared first. Assessment variables can be declared in the Declaration Editor which will make them globally available and also available for auto-completion with Ctrl+Space. Alternatively it is possible to declare assessment variables directly in the script which will make them available in the Script assesslet and the following scripts you might write.
Assessment variables in scripts are declared such as in the following examples:
d = TPT.Double() # data range: floating point double accuracy (64-bit)
f = TPT.Float() # data range: floating point (32-bit)
i = TPT.Int() # data range: -2^31 ... 2^31-1 (= 32-bit signed integer)
b = TPT.Boolean() # data range: "true" and "false"
Additionally for integer variables, the data type can be selectively controlled to reduce large amount of data in big projects.
w = TPT.Int8() # data range: -128 ... 127
r = TPT.Int16() # data range: -2^15 ... 2^15-1
j = TPT.Int32() # data range: -2^31 ... 2^31-1
l = TPT.Int64() # data range: -2^63 ... 2^63-1
c = TPT.UInt8() # data range: 0 ... 255
q = TPT.UInt16() # data range: 0 ... 65535
k = TPT.UInt32() # data range: 0 ... 2^32-1
You can also declare an assessment variable as array or matrix.
a = TPT.Int8Array() # arrays can be specified for any data type
m = TPT.Int16Matrix() # matrices can be specified for any data type
If assessment variables and their values should be part of the report and displayed in the Signal Viewer, you must export them. To export assessment variables declared in the Declaration Editor, the check box Record must be selected, see Declaration Editor. To export assessment variables declared in scripts, use a method that ends with an X
. The X
at the end of the method name tags the variable for export:
f = TPT.DoubleX() # create a double variable and tag it for export
i = TPT.Int16X() # create an int16 variable and tag it for export
b = TPT.BooleanX() # create a boolean variable and tag it for export
m = TPT.DoubleMatrixX() # create a matrix variable and tag it for export
...