This video is taken from the Scripting Learning Track on Ansys Innovation Courses.
Transcript
To add a simulation object and set its properties, you first have to be in layout mode.
When you start a new project, the simulation is in layout mode, but after running your
simulation it is in analysis mode, where adding an object is not allowed.
Next, you have to decide where in the object tree you want to put your objects.
Then, add the object of your choice by entering the script command associated with that object.
To set the properties of an object, you first have to select it and then set the properties.
We will learn various commands associated with each of these steps.
You can check your simulation mode by looking at the top of the simulation window or this
Run/Layout toggle button.
When you see the 'Run' button active here, it means you are in layout mode.
You can do the same by using ¡®layoutmode¡¯ command.
It returns '1' if you are in layoutmode and '0' when in analysis mode.
Finally, to set the simulation into layoutmode, you can use 'switchtolayout' command.
When you add an object using script, by default, it is placed under 'model', which is the root
of the object tree.
For example, here we add a rectangle under model by simply using the command 'addrect'.
If you want to add it under a structure group or an analysis group, you have to specify
the group where the object is to be placed.
You can do this by going into that group using the 'groupscope' command and adding the object
there, or by using the 'addtogroup' command as done here for a rectangle.
After working under a certain sub-group, it is a good idea to set the groupscope back
to 'model'.
To do that, just use "groupscope('::model');".
Groupscope dimer is the same as groupscope model::dimer
The naming of the script commands for adding objects is very intuitive, taking the general
format of add plus the object name.
For example, addtriangle, addfdtd , adddipole, and addindex for adding triangle structure,
fdtd simulation region, dipole source, and index monitor, respectively.
When you add an object, it is automatically selected as shown here with addcircle.
So there is no need to select the object if you are to set its properties right after
adding it.
To select an existing object, use the 'select' command and specify the object name.
For example, here we select the rectangle with name 'rect_1.'
Note that when you select an object with this command, previously selected objects are unselected.
If you want to select an object without unselecting previous ones, use shiftselect as done here
to include 'circle_1' in the selection.
Selectall selects all objects in the current group scope
and selectpartial selects any objects with a given partial name; for example, here we
select all objects with a name that includes the string 'rect'.
To set the properties of the selected object , use the 'set' command and specify the name
and new value of the property you want to modify.
You can use setnamed instead, to select the object you want and set its property at the
same time.
The names of the parameters are mostly the same as they appear in the 'Edit object' window.
However, there can be some exceptions.
For example, if you use the parameter name 'profile' in set command to specify the pml
profile of your boundary, you will get an error message.
The correct name for this parameter is 'pml profile'.
The value of this parameter appears to be a string.
However, parameter values without any inverted triangle in the dropdown menu take numbers,
which correspond to the position of the string in the dropdown menu.
So, if you want to set the profile to standard, you need to use set('pml profile',1);
If you see a parameter with a tick box, you can enable or disable it by setting its value
to 1 or 0.
You can also use true or false.
Note that 'true' and 'false' are pre-defined constants with values of 1 and 0, respectively.
For example, here we enable the property 'same settings on all boundaries' by setting the
property value to 'true'.
If you are not sure what the exact name of a parameter is, use '?get;' or '?set;' after
selecting the object.
To check the current value of a parameter and check if it is a string or a number, select
the object and use ?get('parameter_name');.
You can use getnamed to select the object you want and get its property at the same
time.