Properties example#

This example shows how to use the Common class, which contains properties models. These properties provide for sharing information through all the workflow.

Add new properties#

Before importing the common module, you can add new properties. First create a file that contains the new properties type, Models. Then add a TOML file that sets the needed default values. Finally, import the properties.

[1]:
from models import properties

Perform required imports#

Perform the required imports.

[2]:
import sys
from ansys.aedt.toolkits.common.backend.api import Common

Initialize toolkit#

Initialize the toolkit with the new properties.

[3]:
toolkit = Common(properties)

Get properties#

Get the properties.

[4]:
toolkit.get_properties()
[4]:
{'aedt_version': '2026.1',
 'non_graphical': False,
 'active_project': '',
 'active_design': '',
 'project_list': [],
 'design_list': {},
 'selected_process': 0,
 'use_grpc': True,
 'is_toolkit_busy': False,
 'url': '127.0.0.1',
 'port': 5001,
 'debug': False,
 'toolkit_name': 'example',
 'log_file': 'example_backend.log',
 'state': '',
 'progress': 0,
 'example': {'invented_property': [10], 'test': 'hola'}}

Set property#

Use set_properties to set the new property.

[5]:
set_properties = {"invented_property": [1, 2, 3]}
toolkit.set_properties(set_properties)
toolkit.get_properties()
INFO - Updating internal properties.
[5]:
{'aedt_version': '2026.1',
 'non_graphical': False,
 'active_project': '',
 'active_design': '',
 'project_list': [],
 'design_list': {},
 'selected_process': 0,
 'use_grpc': True,
 'is_toolkit_busy': False,
 'url': '127.0.0.1',
 'port': 5001,
 'debug': False,
 'toolkit_name': 'example',
 'log_file': 'example_backend.log',
 'state': '',
 'progress': 0,
 'example': {'invented_property': [1, 2, 3], 'test': 'hola'}}

Set property directly#

Set the property directly.

[6]:
properties.example.invented_property = [10, 20, 30]
toolkit.get_properties()
[6]:
{'aedt_version': '2026.1',
 'non_graphical': False,
 'active_project': '',
 'active_design': '',
 'project_list': [],
 'design_list': {},
 'selected_process': 0,
 'use_grpc': True,
 'is_toolkit_busy': False,
 'url': '127.0.0.1',
 'port': 5001,
 'debug': False,
 'toolkit_name': 'example',
 'log_file': 'example_backend.log',
 'state': '',
 'progress': 0,
 'example': {'invented_property': [10, 20, 30], 'test': 'hola'}}

Set wrong property#

Set the wrong property. It is not possible to change the property type.

[7]:
set_properties = {"test": True}
toolkit.set_properties(set_properties)
INFO - Updating internal properties.
ERROR - Error occurred during validation of properties field.
[7]:
(False, 'Error occurred during validation of properties field.')