Python Functions & Operators

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.

ParameterTypeRequiredDescription
modulestrYesThe name of the module
categorystrYesThe category of the property
propertystrYesThe name of the property to read

Returns: The property value.

explode = evs.get_module('explode and scale', 'Properties', 'Explode')
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.

ParameterTypeRequiredDescription
modulestrYesThe name of the module
categorystrYesThe category of the property
propertystrYesThe 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.

ParameterTypeRequiredDescription
modulestrYesThe name of the module
categorystrYesThe category of the property
propertystrYesThe name of the property to set
valueanyYesThe new value for the property
evs.set_module('explode and scale', 'Properties', 'Explode', {'Linked': False, 'Value': 1.0})
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.

ParameterTypeRequiredDescription
modulestrYesThe name of the module
categorystrYesThe category of the property
propertystrYesThe name of the property to set
start_valueanyYesThe start value for the interpolation
end_valueanyYesThe end value for the interpolation
percentfloatYesThe percentage (0.0 to 1.0) along the interpolation from start to end
interpolation_methodInterpolationMethodNoThe interpolation method. Default: InterpolationMethod.Linear

The interpolation_method parameter accepts one of the following evs.InterpolationMethod values:

ValueDescription
InterpolationMethod.StepStep interpolation — value jumps at the threshold
InterpolationMethod.LinearLinear interpolation (default)
InterpolationMethod.LinearLogLinear interpolation on a logarithmic scale
InterpolationMethod.CosineCosine interpolation — smooth ease-in/ease-out
InterpolationMethod.CosineLogCosine interpolation on a logarithmic scale
# Interpolate the Explode value from 0.0 to 5.0 at 50%
evs.set_module_interpolated('explode and scale', 'Properties', 'Explode',
    {'Linked': False, 'Value': 0.0},
    {'Linked': False, 'Value': 5.0},
    0.5, evs.InterpolationMethod.Cosine)

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.

ParameterTypeRequiredDescription
modulestrYesThe name of the module
portstrYesThe name of the port
categorystrYesThe category of the property
propertystrYesThe 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.

ParameterTypeRequiredDescription
modulestrYesThe name of the module
portstrYesThe name of the port
categorystrYesThe category of the property
propertystrYesThe 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.

ParameterTypeRequiredDescription
modulestrYesThe name of the module
portstrYesThe name of the port
categorystrYesThe category of the property
propertystrYesThe name of the property to set
valueanyYesThe 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.

ParameterTypeRequiredDescription
modulestrYesThe name of the module
portstrYesThe name of the port
categorystrYesThe category of the property
propertystrYesThe name of the property to set
start_valueanyYesThe start value for the interpolation
end_valueanyYesThe end value for the interpolation
percentfloatYesThe percentage (0.0 to 1.0) along the interpolation from start to end
interpolation_methodInterpolationMethodNoThe 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.

ParameterTypeRequiredDescription
modulestrYesThe name of the module
portstrYesThe 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.

with evs.get_field_info('kriging', 'Output Field') as field:
    print(f"Nodes: {field.number_coordinates}, Cells: {field.number_cells}")
    print(f"Units: {field.coordinate_units}")

    # Read coordinates
    for x, y, z in field.coordinates:
        print(f"  ({x}, {y}, {z})")

    # Read node data
    for i in range(field.number_node_data):
        data = field.get_node_data(i)
        print(f"  {data.name} ({data.units}): {len(data.values)} values")
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:

PropertyTypeDescription
number_coordinatesintThe number of coordinate nodes in the field
number_cellsintThe number of cells in the field
number_node_dataintThe number of node data components
number_cell_dataintThe number of cell data components
coordinate_unitsstrThe units used for coordinates
coordinateslist of (x, y, z) tuplesThe node coordinate tuples, loaded lazily
cell_centerslist of (x, y, z) tuplesThe cell center coordinate tuples, loaded lazily

Methods:

MethodReturnsDescription
get_node_data(index)FieldDataGets the node data component at the specified index. Raises ValueError if the index is out of range.
get_cell_data(index)FieldDataGets the cell data component at the specified index. Raises ValueError if the index is out of range.
close()NoneDisposes 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:

PropertyTypeDescription
namestrThe name of the data component
unitsstrThe units associated with the data
is_logboolTrue if the data component uses log processing
valueslist of float or tuplesThe 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:

KeyDescription
AuthorThe application author
OrganizationThe organization
FilenameThe application filename
ExecutingScriptThe currently executing script
evs.get_modules()

Gets a list of all module names in the application.

Returns: list of str — module names.

for name in evs.get_modules():
    print(f"{name}: {evs.get_module_type(name)}")
evs.get_module_type(module)

Gets the type of a module given its name.

ParameterTypeRequiredDescription
modulestrYesThe name of the module

Returns: str — the module type.

evs.get_module_position(module)

Gets the position of a module in the network editor.

ParameterTypeRequiredDescription
modulestrYesThe 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.

ParameterTypeRequiredDescription
modulestrYesThe current name of the module
suggested_namestrYesThe desired new name

Returns: str — the actual new name of the module.

evs.delete_module(module)

Deletes a module from the application.

ParameterTypeRequiredDescription
modulestrYesThe 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.

ParameterTypeRequiredDescription
modulestrYesThe module type to instance
suggested_namestrYesThe suggested name for the new module
xintYesThe x coordinate in the network editor
yintYesThe y coordinate in the network editor

Returns: str — the actual name of the instanced module.

name = evs.instance_module('Estimation.kriging', 'my kriging', 100, 200)
print(f"Created module: {name}")

Module Connections

evs.connect(starting_module, starting_port, ending_module, ending_port)

Connects a port on one module to a port on another module.

ParameterTypeRequiredDescription
starting_modulestrYesThe source module
starting_portstrYesThe port on the source module
ending_modulestrYesThe destination module
ending_portstrYesThe port on the destination module

Returns: bool — True if successful.

evs.connect('kriging', 'Output Field', 'cut', 'Input Field')
evs.disconnect(starting_module, starting_port, ending_module, ending_port)

Disconnects two previously connected module ports.

ParameterTypeRequiredDescription
starting_modulestrYesThe source module
starting_portstrYesThe port on the source module
ending_modulestrYesThe destination module
ending_portstrYesThe 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.

for i in range(10000):
    evs.check_cancel()
    # ... do work ...
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.suspend()
evs.set_module('kriging', 'Properties', 'Allow Run', True)
evs.set_module('kriging', 'Properties', 'Variogram Range', 500.0)
evs.resume()
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.

ParameterTypeRequiredDescription
numberfloatYesThe number to round
digitsintYesThe number of significant digits

Returns: float — the rounded value.

evs.sigfig(123456.789, 4)  # Returns 123500.0
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().

ParameterTypeRequiredDescription
numberfloatYesThe number to format
digitsintNoThe number of significant digits. Default: 6
include_thousands_separatorsboolNoWhether to include thousands separators. Default: True
preserve_trailing_zerosboolNoWhether to preserve trailing zeros. Default: False

Returns: str — the formatted number.

evs.fn(1234567.89)           # "1,234,570"
evs.fn(1234567.89, 3)        # "1,230,000"
evs.fn(1234567.89, 6, False) # "1234570"
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().

ParameterTypeRequiredDescription
numberfloatYesThe number to format
adapt_sizefloatYesThe reference value to adapt precision to
digitsintNoThe number of significant digits. Default: 6
include_thousands_separatorsboolNoWhether to include thousands separators. Default: True
preserve_trailing_zerosboolNoWhether 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.

stage = evs.get_export_stage()

# Run initialization code at the start of an export
stage.handle_init(lambda: print("Export starting"))

# Handle a specific module being exported
stage.handle_module('kriging', lambda: print("Kriging exported"))

# Handle sequence states with state number and name
stage.handle_sequence('scripted sequence', lambda num, name: print(f"State {num}: {name}"))

# Run finalization code at the end of an export
stage.handle_finalize(lambda: print("Export complete"))
evs.ExportStage

Represents the current export stage and provides handler methods for responding to specific stages. Constructed by get_export_stage().

Properties:

PropertyTypeDescription
stageExportStage.StagesThe current stage of the export process
modulestrThe module being exported (empty string if not applicable)
state_numberintThe current sequence state number (-1 if not applicable)
state_namestrThe current sequence state name (empty string if not applicable)

Stages:

StageDescription
Stages.NOT_EXPORTINGEVS is not currently exporting
Stages.START_EXPORTThe export process just started
Stages.START_MODULEThe specified module is starting the export process
Stages.END_SEQUENCE_STATEA sequence state of the specified module was just exported
Stages.END_MODULEThe specified module was just exported
Stages.END_EXPORTThe export process just finished

Handler Methods:

MethodParametersDescription
handle_init(func)func — a function taking no argumentsRuns func if currently in the START_EXPORT stage
handle_finalize(func)func — a function taking no argumentsRuns func if currently in the END_EXPORT stage
handle_module(module, func)module — module name, func — a function taking no argumentsRuns 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.

ParameterTypeRequiredDescription
namestrYesThe name of the Python asset to import

Returns: module — the imported Python module.

Raises: ModuleNotFoundError if no Python asset exists with the given name.

helpers = evs.import_asset('my_utilities')
helpers.do_something()

Date Conversions (evs_util)

The evs_util module provides functions for converting between three date representations used in EVS:

FormatExampleDescription
EVS date string"2024-06-15T14:30:00"ISO 8601 format used by EVS module properties
Python datetimedatetime.datetime(2024, 6, 15, 14, 30)Standard Python datetime.datetime object
Excel date number45458.604Days since 1899-12-30, used in Excel spreadsheets

Each function converts from one format to another. The naming convention is {source}_to_{target}:

FunctionConverts FromConverts To
evs_util.evsdate_to_datetime(d)EVS date stringPython datetime
evs_util.datetime_to_evsdate(d)Python datetimeEVS date string
evs_util.datetime_to_excel(d)Python datetimeExcel date number
evs_util.evsdate_to_excel(d)EVS date stringExcel date number
evs_util.excel_to_datetime(d)Excel date numberPython datetime
evs_util.excel_to_evsdate(d)Excel date numberEVS date string
import evs_util
import datetime

# Convert an EVS date string to a Python datetime
dt = evs_util.evsdate_to_datetime("2024-06-15T14:30:00")

# Convert to an Excel date number
excel_num = evs_util.datetime_to_excel(dt)

# Convert back to an EVS date string
evs_date = evs_util.excel_to_evsdate(excel_num)

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.

ParameterTypeRequiredDescription
assertionboolYesThe condition to test
error_on_failstrYesThe error message to display if the assertion is false
value = evs.get_module('kriging', 'Properties', 'Allow Run')
evs.test(value == True, "Expected Allow Run to be enabled")