Jython Script Examples

This section provides examples of how Jython scripts appear when used in an Isight editor, as well as simple Jython scripts that could be used in the Epilogue of a component or in the Script component.

Example: Testing Parameter Values

The following script tests that the value of the parameter parm1 is between 0.0 and 100.0 and throws an exception if it is not, causing the whole component to fail. The parameter parm2 is checked separately for being between 0.09 and 15.0 (0.09 < parm2 < 15.0 is a Jython shorthand for 0.09 < parm2 and parm2 < 15.0).

Note: The new operator is not used when creating a new instance of a Java class like RtException.

from com.engineous.sdk.runtime import RtException
if parm1 <= 0.0 or parm1 >= 100.0 :
raise RtException("Parameter parm1 is out of range")
if not (0.09 < parm2 < 15.0):
raise RtException("Parameter parm2 is out of range")

Example: Logging Results

You can use a script to log information about results.

The following script logs an Information message about some results and adds a warning if the results are outside the expected range.

print "response is", responseParm, "  variation is", variation
if responseParm > 10.0 or variation > 2:
jobLog.logWarn("Results are not reliable")
isValid = 0
else:
isValid = 1

In addition, an output parameter isValid is set to indicate if the results are valid.