The get and
set methods are used to access and assign, respectively, property values in the different parts of the model object. To assign individual elements of a vector or matrix, the
setIndex method is used. The property values can be of the basic data types:
String,
int,
double, and
boolean, as well as vectors or matrices of these types (1D or 2D arrays).
The get,
set, and
create methods (described in the previous section) are also accessible from the model tree by right-clicking and selecting
Copy as Code to Clipboard.
The family of get methods is used to retrieve the values of properties. For example, the
getDouble method can be used to retrieve the value of the predefined element size property
hauto for a mesh and store it in a variable
hv:
See the section “Example Code” on page 33 below for more information on the property
hauto.
The syntax for assignment using the set method is exemplified by this line of code, which sets the title of a plot group
pg1:
The first argument is a string with the name of the property, in the above example "title". The second argument is the value and can be a basic type as indicated by the table below.
Using the set method for an object returns the object itself. This allows you to append multiple calls to
set as follows:
The previous line of code assigns values to both the edgecolor and
edges properties of the plot group
pg1 and is equivalent to the two lines:
In this case, the set method returns a plot group object.
The setIndex method is used to assign a value to a 1D or 2D array element at a position given by one or two indices (starting from index 0).
For the setIndex method in general, use one of these alternatives to set the value of a single element:
The name argument is a string with the name of the property. The
value argument is a string representation of the value. The indices start at 0, for example:
The setIndex method returns an object of the same type, which means that
setIndex methods can be appended just like the
set method.
The method setIndex and
set can both be used to assign values in ragged arrays. For example, consider a ragged array with 2 rows. The code statements:
For object types for which the set,
setIndex, and
get methods can be used, the following additional methods are available, exemplified by the case of a Heat Transfer in Solids physics interface:
In the above example, getDouble is used to retrieve the value of the property
hauto, which corresponds to the
Element Size parameter
Predefined in the
Settings window of the
Size node under the
Mesh node. This setting is available when the
Sequence type is set to
User-controlled mesh, in the
Settings window of the
Mesh node.