Snippets are existing lines of code that can quickly and easily be inserted in the command line, saving you from repetitive typing. As you use the ACT Console, you can insert any of the snippets that ANSYS supplies for ACT-specific commands. Additionally, you can begin building your own library of snippets to either supplement or replace the supplied snippets with your own custom snippets.
The ExtAPI snippet inserts ExtAPI. in the
command line, providing you with immediate access to the API. From the autocomplete
options in the tooltip, you can then begin selecting additional attributes to build your
command.
The Snippet Template snippet provides sample code for swapping two variables. The comments explain how a snippet can contain editable fields, which are automatically selected for modification when the snippet is inserted. When a field is selected, you can type a new value to override the default value or let the default value remain. Pressing the Tab key moves the cursor to the next editable field.
The Helpers folder provides snippets for frequently used commands. Descriptions follow of all snippets in this folder:
Project. Inserts
ExtAPI.DataModel.Project, providing access to the
project, which is the top level of the hierarchy in the Mechanical tree. If
you wanted to explore the model tree and interact with first-level objects,
you would use the tooltip to select the Model attribute and then the
attribute for the first-level object. The next two snippets in this folder
provide object access, as do the following command line entries:
ExtAPI.DataModel.Project.Model.Connections
accesses the Connections object.
ExtAPI.DataModel.Project.Model.NamedSelections
accesses the NamedSelections
object.
Mesh. Inserts mesh =
ExtAPI.DataModel.Project.Model.Mesh, providing access to the
Mesh object.
Geometry. Inserts geometry =
ExtAPI.DataModel.Project.Model.Geometry, providing access to
the Geometry object.
Analysis. Inserts analysis =
ExtAPI.DataModel.Project.Model.Analyses[0], providing access
to the first analysis of the model. As indicated earlier, Python starts
counting at 0 rather than 1.
ObjectsByName. Inserts solution =
ExtAPI.DataModel.Tree.GetObjectsByName("Solution"),
providing access to a list of all solutions. To apply this function with
pressure, you use:pressure =
ExtAPI.DataModel.Tree.GetObjectsByName("pressure").
solution = ExtAPI.DataModel.Tree.GetObjectsByName("pressure")
PathToFirstActiveObject. Inserts
path_to_object =
ExtAPI.DataModel.Tree.GetPathToFirstActiveObject(),
providing access to the full path that must be typed to go to the first
object that is selected in the tree.
ObjectsByType. Inserts
coordinate_system_list =
ExtAPI.DataModel.Tree.GetObjectsByType(DataModelObjectCategory.CoordinateSystem),
where DataModelObjectCategory is the enumeration
containing all types. To apply this function with pressure, you use:
pressure_list = ExtAPI.DataModel.Tree.GetObjectsByType(DataModelObjectCategory.Pressure)
Active Objects. Inserts active_objects =
ExtAPI.DataModel.Tree.ActiveObjects, providing a list of all
selected objects in the tree.
FirstActiveObject. Inserts
first_active_object =
ExtAPI.DataModel.Tree.FirstActiveObject, providing access to
the first of all selected objects.
Quantity. Inserts Quantity("1
[mm]", providing a command method in which you can declare
values. Three examples follow:
pres = ExtAPI.DataModel.Project.Model.Analyses[0].AddPressure()
pres.Magnitude.Inputs[0].DiscreteValues = [Quantity('0 [sec]'), Quantity('1 [sec]'), Quantity('2 [sec]')]pres.Magnitude.Output.DiscreteValues = [Quantity('0 [Pa]'), Quantity('50 [Pa]'), Quantity('100 [Pa]')]
Lastly, the Examples folder provides snippets that you can use as templates. For example, the Add Pressure Template snippet shows how to create a pressure on the first face of the first body of the first part.
To see all snippets, including those predefined for standard Python commands, you can press Ctrl + space when nothing is entered in the command line and then scroll through the autocompletion suggestions, which includes both variables and snippets. Although you can remove snippets for ACT-specific commands by deleting them from the Snippets panel, you cannot delete the snippets predefined for standard Python commands. For more information, see Using Snippets.