set_variable#

VariableManager.set_variable(name: str | list[str], expression: str | list | None = None, read_only: bool | list[bool] = False, hidden: bool | list[bool] = False, description: str | list[str] | None = None, sweep: bool | list[bool] = True, overwrite: bool = True, is_post_processing: bool | list[bool] = False, circuit_parameter: bool | list[bool] = True) → bool#

Set the value of one or more design properties or project variables.

Parameters:
namestr or list[str]

Name of the design property or project variable ($var), or a list of names. If a variable does not exist, a new one is created and a value is set. When a list is provided, all other parameters can also be lists of the same length.

expressionstr or list, optional

Valid string expression within the AEDT design and project structure, or a list of expressions. For example, "3*cos(34deg)".

read_onlybool or list[bool], optional

Whether to set the variable(s) to read-only. The default is False.

hiddenbool or list[bool], optional

Whether to hide the variable(s). The default is False.

descriptionstr or list[str], optional

Text to display for the variable(s) in the Properties window. The default is None.

sweepbool or list[bool], optional

Whether to include variable(s) in solution indexing for faster post-processing. The default is True.

overwritebool, optional

Whether to overwrite existing values. The default is True.

is_post_processingbool or list[bool], optional

Whether to define postprocessing variable(s). The default is False.

circuit_parameterbool or list[bool], optional

Whether to define a parameter in a circuit design or a local parameter. The default is True.

Returns:
bool

True when successful, False when failed.

References

>>> oProject.ChangeProperty
>>> oDesign.ChangeProperty

Examples

>>> from ansys.aedt.core import Maxwell3d
>>> aedtapp = Maxwell3d(version="2026.1")

Set the value of design property p1 to "10mm", creating the property if it does not already exist.

>>> aedtapp.variable_manager.set_variable("p1", expression="10mm")

Set the value of design property p1 to "20mm" only if the property does not already exist.

>>> aedtapp.variable_manager.set_variable("p1", expression="20mm", overwrite=False)

Set the value of design property p2 to "10mm", creating the property if it does not already exist. Also make it read-only and hidden and add a description.

>>> aedtapp.variable_manager.set_variable(
...     name="p2",
...     expression="10mm",
...     read_only=True,
...     hidden=True,
...     description="This is the description of this variable.",
... )

Set the value of the project variable $p1 to "30mm", creating the variable if it does not exist.

>>> aedtapp.variable_manager.set_variable("$p1", expression="30mm")

Set multiple variables at once using lists (single API call).

>>> aedtapp.variable_manager.set_variable(name=["length", "width", "height"], expression=["10mm", "5mm", "2mm"])