ANSYS Workbench scripting follows an object-based approach, where interaction with data is defined in terms of objects. Objects have properties that can be used to get or set data values, and methods that use or modify the data. In terms of the ANSYS Workbench concepts described in ANSYS Workbench Project and Data Model Concepts, objects are references to data entities in the data model, and the methods are commands and queries which operate on those entities.
For example, a Parameter is a data entity that has properties such as description, value, and expression, and has methods that operate on the parameter to (for example) delete it or determine which other parts of the data model are associated with the parameter.
ANSYS Workbench objects fall into two general categories: data containers and data entities. The basic process for operating on these objects is:
Query for either a data container
or data entity objects. Queries are implemented as methods
on both data container and data entity objects, and they most often
start with Get (e.g., GetFiles, GetSystem, GetComponent). These methods return references to objects that are assigned
to variables. The variables can then be used to access object properties
and methods. To illustrate this process, consider the Design of Experiments
(DOE) data container that includes a data entity for the DOE model,
which in turn contains a data entity for the input parameters. To
query the input parameter object, first query the DOE model from the
data container, and then query the input parameter from the DOE model:
DOEModel = DOEDataContainer.GetModel() InputParameter = DOEModel.GetParameter(Name="P1")
In most instances, the variable for a data reference will be reused later in the journal or script so that queries do not need to be re-executed. However, there are some instances (e.g., System Coupling Variables), where re-executing the query can clarify the context that is used to access the object. In those situations, journal variables are not reused and queries are generated each time an object is referenced.
Interrogate and modify object properties. If the query returns a reference to a data entity, you can interrogate its properties and modify those that are not identified as “Read-Only” in the Reference section of this guide. Properties are accessed by appending a dot and the property name to the variable assigned to the object reference. For example, once a reference to an input parameter is obtained, you can modify its classification (or Nature Property) to reflect that it is a continuous or discrete parameter.
inputParameter.Nature = "NatureContinuous"
Call methods on objects. In addition to properties, most objects provide methods that operate on internal data. To call a method on an object, append a dot, the method name, and a comma-separated argument list in closed parentheses. A method's required and optional arguments are also documented in the Reference section of this guide. Continuing the input parameter example, you can specify a restricted set of Manufacturable Values for a parameter by calling the AddLevels method on the input parameter object and by constructing a list of values and assigning it to the Levels argument.
inputParameter.AddLevels( Levels=["65", "70", "75", "80"])
Typical examples are provided in Usage Examples. These examples demonstrate how to query objects and how to invoke methods on those objects for the desired result. Use the Reference section at the end of this document for a complete list of all available data container objects, and the data entities, methods, properties, and arguments associated with each.