Configuring the Python® Scripting block
This section shows you how to configure, add, and remove Python Scripting block fields, as well as how to create a Python script to be used by the block.
On this page you can find out about:
NOTE: CSense provides secure native blocks and operations for building analytics and solutions. The native capabilities provided by CSense can be extended by making use of this feature. When making use of this feature, please ensure that you have validated your extended functions to ensure that they perform as intended and do not introduce stability or security risks to your production system. Do not use scripts or components from untrusted sources.
Script Editor
Enter your Python® script in the script editor. The script editor accepts any character.
In the script, you can:
-
Define new local variables.
-
Define new local functions.
-
Access input field values, qualities, and timestamps.
-
Set output field values, qualities, and timestamps.
Script Validation
To validate the script syntax, press the Validate button underneath the script window or press the F7 key.
Any syntax errors or warnings detected during script verification are reported in the output window below the script area. For each error or warning detected, an issue number, the script line number, and a description of the issue are given. Double-click on a reported error or warning in the output window to jump to the position in the script where it has been detected.
NOTE: Script validation detects syntax errors only. It does not detect runtime errors.
Inputs Tab
All Input fields are shown in this tab and cannot be created or removed.
Outputs Tab
The names and types of all output fields are displayed here.
New fields can be added manually or imported from this tab.
Existing fields can be exported or removed.
Adding a field manually
To add a new output field from the Outputs tab:
-
Go to the Outputs tab.
-
Enter a name for the new field in the text field on the Outputs tab.
-
Select one of the following types for the field: DoubleField, StringField, IntegerField.
-
Click on the "+" button to add the new field. (The "+" turns green once a name has been entered.)
The output field you have added is now available to use in your Python script. See the Object: outputfield topic for more information.
Importing fields
-
Create a .csv file with field names and field types.
-
Column headers must be included at the top of the file as follows: Name,Type
-
Each line in the file must be of this form: <name>,<type>
-
Valid types for output fields are: DoubleField, StringField, IntegerField.
-
-
At the bottom of the tab, click the "Import" icon.
-
Browse to your newly created .csv file, select it, and click OK.
If the file you created is incorrectly formatted, or if a type you have specified is invalid, or if you have specified duplicate fields, a message will inform you of the error and the action taken.
Exporting fields
-
At the bottom of the tab, click the "Export" icon.
-
Browse to where you want your file to be created, specify a file name, and click OK.
Removing a field
To remove an output field:
-
Go to the Outputs tab.
-
Select the name of the field you wish to remove from the list of output fields.
-
Click on the "x" button to remove the field.
Remember to update your Python script so that it does not make reference to the object you have removed.
Related topics: