Python Functions & Operators
Earth Volumetric Studio supports Python 3.12 and 3.13. It will use the highest supported system installed version by default, but can be configured in options.
A listing of Python Functions & Operators can be found at python.org. Below are links to relevant pages:
Please note: C Tech does not provide Python programming or syntax assistance as a part of Technical Support (included with valid subscriptions). Python scripting and functionality is provided as an advanced feature of Earth Volumetric Studio, but is not required to use the basic functionality.
Below are Earth Volumetric Studio specific functions and classes which provide means to get and set parameters, read field data, and act upon the modules in the libraries and network. All functions below are available through the evs module unless otherwise noted.
Module Properties
These functions read and write property values on modules. For a detailed walkthrough with examples, see Accessing Properties Using Python.
evs.get_module(module, category, property)
Gets a property value from a module within the application.
| Parameter | Type | Required | Description |
|---|---|---|---|
module | str | Yes | The name of the module |
category | str | Yes | The category of the property |
property | str | Yes | The name of the property to read |
Returns: The property value.
evs.get_module_extended(module, category, property)
Gets an extended property value from a module within the application. Extended values include additional metadata beyond the basic value.
| Parameter | Type | Required | Description |
|---|---|---|---|
module | str | Yes | The name of the module |
category | str | Yes | The category of the property |
property | str | Yes | The name of the property to read |
Returns: The extended property value.
evs.set_module(module, category, property, value)
Sets a property value on a module within the application.
| Parameter | Type | Required | Description |
|---|---|---|---|
module | str | Yes | The name of the module |
category | str | Yes | The category of the property |
property | str | Yes | The name of the property to set |
value | any | Yes | The new value for the property |
evs.set_module_interpolated(module, category, property, start_value, end_value, percent, interpolation_method)
Sets a property value by interpolating between two values. Useful for animating properties across sequence states.
| Parameter | Type | Required | Description |
|---|---|---|---|
module | str | Yes | The name of the module |
category | str | Yes | The category of the property |
property | str | Yes | The name of the property to set |
start_value | any | Yes | The start value for the interpolation |
end_value | any | Yes | The end value for the interpolation |
percent | float | Yes | The percentage (0.0 to 1.0) along the interpolation from start to end |
interpolation_method | InterpolationMethod | No | The interpolation method. Default: InterpolationMethod.Linear |
The interpolation_method parameter accepts one of the following evs.InterpolationMethod values:
| Value | Description |
|---|---|
InterpolationMethod.Step | Step interpolation β value jumps at the threshold |
InterpolationMethod.Linear | Linear interpolation (default) |
InterpolationMethod.LinearLog | Linear interpolation on a logarithmic scale |
InterpolationMethod.Cosine | Cosine interpolation β smooth ease-in/ease-out |
InterpolationMethod.CosineLog | Cosine interpolation on a logarithmic scale |
Port Properties
These functions read and write property values on module ports.
evs.get_port(module, port, category, property)
Gets a value from a port on a module within the application.
| Parameter | Type | Required | Description |
|---|---|---|---|
module | str | Yes | The name of the module |
port | str | Yes | The name of the port |
category | str | Yes | The category of the property |
property | str | Yes | The name of the property to read |
Returns: The port property value.
evs.get_port_extended(module, port, category, property)
Gets an extended value from a port on a module within the application.
| Parameter | Type | Required | Description |
|---|---|---|---|
module | str | Yes | The name of the module |
port | str | Yes | The name of the port |
category | str | Yes | The category of the property |
property | str | Yes | The name of the property to read |
Returns: The extended port property value.
evs.set_port(module, port, category, property, value)
Sets a property value on a port in a module within the application.
| Parameter | Type | Required | Description |
|---|---|---|---|
module | str | Yes | The name of the module |
port | str | Yes | The name of the port |
category | str | Yes | The category of the property |
property | str | Yes | The name of the property to set |
value | any | Yes | The new value for the property |
evs.set_port_interpolated(module, port, category, property, start_value, end_value, percent, interpolation_method)
Sets a port property value by interpolating between two values. Accepts the same evs.InterpolationMethod values as set_module_interpolated.
| Parameter | Type | Required | Description |
|---|---|---|---|
module | str | Yes | The name of the module |
port | str | Yes | The name of the port |
category | str | Yes | The category of the property |
property | str | Yes | The name of the property to set |
start_value | any | Yes | The start value for the interpolation |
end_value | any | Yes | The end value for the interpolation |
percent | float | Yes | The percentage (0.0 to 1.0) along the interpolation from start to end |
interpolation_method | InterpolationMethod | No | The interpolation method. Default: InterpolationMethod.Linear |
Reading Field Data
These functions and classes allow Python scripts to read the contents of field data from module ports. This is useful for extracting coordinates, node data, and cell data from computed fields.
evs.get_field_info(module, port)
Gets a FieldInfo object for reading field data from a module port. The returned object should be used within a with statement, or you must call close() manually when finished.
| Parameter | Type | Required | Description |
|---|---|---|---|
module | str | Yes | The name of the module |
port | str | Yes | The name of the port containing a field to read |
Returns: FieldInfo β a field reader for accessing coordinates and data.
Raises: ValueError if the field reader cannot be created for the specified module and port.
evs.FieldInfo
Represents a field, providing access to its coordinates, node data, and cell data. Should be used within a with statement to ensure resources are properly released.
Properties:
| Property | Type | Description |
|---|---|---|
number_coordinates | int | The number of coordinate nodes in the field |
number_cells | int | The number of cells in the field |
number_node_data | int | The number of node data components |
number_cell_data | int | The number of cell data components |
coordinate_units | str | The units used for coordinates |
coordinates | list of (x, y, z) tuples | The node coordinate tuples, loaded lazily |
cell_centers | list of (x, y, z) tuples | The cell center coordinate tuples, loaded lazily |
Methods:
| Method | Returns | Description |
|---|---|---|
get_node_data(index) | FieldData | Gets the node data component at the specified index. Raises ValueError if the index is out of range. |
get_cell_data(index) | FieldData | Gets the cell data component at the specified index. Raises ValueError if the index is out of range. |
close() | None | Disposes the underlying field reader. Required if not using a with statement. |
evs.FieldData
Represents one node or cell data component of a field. Returned by FieldInfo.get_node_data() and FieldInfo.get_cell_data().
Properties:
| Property | Type | Description |
|---|---|---|
name | str | The name of the data component |
units | str | The units associated with the data |
is_log | bool | True if the data component uses log processing |
values | list of float or tuples | The data values. Log-processed values are exponentiated. Vector data will be a list of tuples. |
Application and Module Management
evs.get_application_info()
Gets basic information about the current application.
Returns: dict β a dictionary with the following keys:
| Key | Description |
|---|---|
Author | The application author |
Organization | The organization |
Filename | The application filename |
ExecutingScript | The currently executing script |
evs.get_modules()
Gets a list of all module names in the application.
Returns: list of str β module names.
evs.get_module_type(module)
Gets the type of a module given its name.
| Parameter | Type | Required | Description |
|---|---|---|---|
module | str | Yes | The name of the module |
Returns: str β the module type.
evs.get_module_position(module)
Gets the position of a module in the network editor.
| Parameter | Type | Required | Description |
|---|---|---|---|
module | str | Yes | The name of the module |
Returns: tuple of (x, y) β the module’s position coordinates.
evs.rename_module(module, suggested_name)
Renames a module and returns the actual new name. The actual name may differ from the suggested name if a module with that name already exists.
| Parameter | Type | Required | Description |
|---|---|---|---|
module | str | Yes | The current name of the module |
suggested_name | str | Yes | The desired new name |
Returns: str β the actual new name of the module.
evs.delete_module(module)
Deletes a module from the application.
| Parameter | Type | Required | Description |
|---|---|---|---|
module | str | Yes | The name of the module to delete |
Returns: bool β True if successful.
evs.instance_module(module, suggested_name, x, y)
Creates a new instance of a module in the application at the specified position.
| Parameter | Type | Required | Description |
|---|---|---|---|
module | str | Yes | The module type to instance |
suggested_name | str | Yes | The suggested name for the new module |
x | int | Yes | The x coordinate in the network editor |
y | int | Yes | The y coordinate in the network editor |
Returns: str β the actual name of the instanced module.
Module Connections
evs.connect(starting_module, starting_port, ending_module, ending_port)
Connects a port on one module to a port on another module.
| Parameter | Type | Required | Description |
|---|---|---|---|
starting_module | str | Yes | The source module |
starting_port | str | Yes | The port on the source module |
ending_module | str | Yes | The destination module |
ending_port | str | Yes | The port on the destination module |
Returns: bool β True if successful.
evs.disconnect(starting_module, starting_port, ending_module, ending_port)
Disconnects two previously connected module ports.
| Parameter | Type | Required | Description |
|---|---|---|---|
starting_module | str | Yes | The source module |
starting_port | str | Yes | The port on the source module |
ending_module | str | Yes | The destination module |
ending_port | str | Yes | The port on the destination module |
Returns: bool β True if successful.
Execution Control
evs.check_cancel()
Checks whether the user has requested to cancel the script. If a cancellation has been requested, the script will stop at that point. Insert this in loops that may run for a long time so that canceling the script remains possible.
evs.suspend()
Suspends the execution of the application until resume() is called. Use this when making multiple property changes to prevent the application from updating between each change.
evs.resume()
Resumes the execution of the application, causing any operations that were suspended to run.
evs.refresh()
Refreshes the viewer and processes all mouse and keyboard actions in the application.
Use With Caution
This is a potentially unsafe operation under certain circumstances that are hard to predict.
At each occurrence of this function, your script will catch up to behave more like manual actions. In most cases this is the only way to see the consequences of commands reflected in the viewer during script execution.
If your script is malfunctioning with this command, try removing or commenting out all occurrences. This command is not recommended within Python scripts executed by the trigger script module.
evs.is_module_executed()
Returns whether the script is being executed by a module (such as trigger script) as opposed to being run directly by the user.
Returns: bool β True if executed by a module, False when the user executes directly (e.g., hitting play in the script window).
Number Formatting
evs.sigfig(number, digits)
Rounds a number to a specified number of significant figures.
| Parameter | Type | Required | Description |
|---|---|---|---|
number | float | Yes | The number to round |
digits | int | Yes | The number of significant digits |
Returns: float β the rounded value.
evs.fn(number, digits, include_thousands_separators, preserve_trailing_zeros)
Formats a number as a string using a specified number of significant figures. Also available as evs.format_number().
| Parameter | Type | Required | Description |
|---|---|---|---|
number | float | Yes | The number to format |
digits | int | No | The number of significant digits. Default: 6 |
include_thousands_separators | bool | No | Whether to include thousands separators. Default: True |
preserve_trailing_zeros | bool | No | Whether to preserve trailing zeros. Default: False |
Returns: str β the formatted number.
evs.fn_a(number, adapt_size, digits, include_thousands_separators, preserve_trailing_zeros)
Formats a number as a string, adapting the precision to the magnitude of a second number. This is useful when formatting a value relative to a step size or range. Also available as evs.format_number_adaptive().
| Parameter | Type | Required | Description |
|---|---|---|---|
number | float | Yes | The number to format |
adapt_size | float | Yes | The reference value to adapt precision to |
digits | int | No | The number of significant digits. Default: 6 |
include_thousands_separators | bool | No | Whether to include thousands separators. Default: True |
preserve_trailing_zeros | bool | No | Whether to preserve trailing zeros. Default: False |
Returns: str β the formatted number.
Export Scripting
The export scripting API allows Python scripts to respond to events during a web scene export. When the export web scene module writes a CTWS file, it triggers the attached Python script at each stage of the process. Use get_export_stage() to determine the current stage and respond accordingly.
evs.get_export_stage()
Gets the current export stage and related information.
Returns: ExportStage β an object describing the current stage of the export process.
evs.ExportStage
Represents the current export stage and provides handler methods for responding to specific stages. Constructed by get_export_stage().
Properties:
| Property | Type | Description |
|---|---|---|
stage | ExportStage.Stages | The current stage of the export process |
module | str | The module being exported (empty string if not applicable) |
state_number | int | The current sequence state number (-1 if not applicable) |
state_name | str | The current sequence state name (empty string if not applicable) |
Stages:
| Stage | Description |
|---|---|
Stages.NOT_EXPORTING | EVS is not currently exporting |
Stages.START_EXPORT | The export process just started |
Stages.START_MODULE | The specified module is starting the export process |
Stages.END_SEQUENCE_STATE | A sequence state of the specified module was just exported |
Stages.END_MODULE | The specified module was just exported |
Stages.END_EXPORT | The export process just finished |
Handler Methods:
| Method | Parameters | Description |
|---|---|---|
handle_init(func) | func β a function taking no arguments | Runs func if currently in the START_EXPORT stage |
handle_finalize(func) | func β a function taking no arguments | Runs func if currently in the END_EXPORT stage |
handle_module(module, func) | module β module name, func β a function taking no arguments | Runs func if the specified module was just exported |
handle_sequence(module, func) | module β module name, func β a function taking (state_number, state_name) | Runs func if a sequence state of the specified module was just exported |
Python Assets
evs.import_asset(name)
Imports a Python module included in the Python Assets section of the Application Properties. This is used instead of a standard import statement when working with EVS presentation files or packaged data, since Python assets are embedded within the application rather than stored as separate files on disk.
| Parameter | Type | Required | Description |
|---|---|---|---|
name | str | Yes | The name of the Python asset to import |
Returns: module β the imported Python module.
Raises: ModuleNotFoundError if no Python asset exists with the given name.
Date Conversions (evs_util)
The evs_util module provides functions for converting between three date representations used in EVS:
| Format | Example | Description |
|---|---|---|
| EVS date string | "2024-06-15T14:30:00" | ISO 8601 format used by EVS module properties |
| Python datetime | datetime.datetime(2024, 6, 15, 14, 30) | Standard Python datetime.datetime object |
| Excel date number | 45458.604 | Days since 1899-12-30, used in Excel spreadsheets |
Each function converts from one format to another. The naming convention is {source}_to_{target}:
| Function | Converts From | Converts To |
|---|---|---|
evs_util.evsdate_to_datetime(d) | EVS date string | Python datetime |
evs_util.datetime_to_evsdate(d) | Python datetime | EVS date string |
evs_util.datetime_to_excel(d) | Python datetime | Excel date number |
evs_util.evsdate_to_excel(d) | EVS date string | Excel date number |
evs_util.excel_to_datetime(d) | Excel date number | Python datetime |
evs_util.excel_to_evsdate(d) | Excel date number | EVS date string |
Testing
evs.test(assertion, error_on_fail)
Asserts that a condition is true. If the assertion is false, the specified error message is printed as an error.
| Parameter | Type | Required | Description |
|---|---|---|---|
assertion | bool | Yes | The condition to test |
error_on_fail | str | Yes | The error message to display if the assertion is false |