Supplied Snippets

Descriptions follow of all supplied snippets:

The snippet ExtAPI inserts ExtAPI. in the command line, providing you with immediate access to the ACT API. From the autocomplete options in the tooltip, you can then begin selecting members to build your command.

The snippet Snippet Template 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 folder Helpers provides snippets for frequently used commands:

  • Project. Inserts project = DataModel.Project, providing access to the project, which is the top level of the hierarchy in the Mechanical tree. To interact with first-level objects in the tree, you would then type a period and use the list of suggestion to select the attribute Model and then the attribute for the first-level object. For example, these command line entries provide access to the first-level tree objects Connections and Named Selections:

    • project=DataModel.Project.Model.Connections

    • project=DataModel.Project.Model.NamedSelections

    The snippets Mesh and Geometry provide examples of easier methods for accessing first-level objects.

  • Mesh. Inserts mesh = Model.Mesh, providing access to the object Mesh.

  • Geometry. Inserts geometry = Model.Geometry, providing access to the object Geometry.

  • Analysis. Inserts analysis = 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 = DataModel.GetObjectsByName("Solution"), providing access to a list of all solutions. To apply this function with pressure, you use solution = DataModel.GetObjectsByName("pressure").

  • PathToFirstActiveObject. Inserts path_to_object = 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 = DataModel.GetObjectsByType(DataModelObjectCategory.CoordinateSystem), where DataModelObjectCategory is the enumeration containing all types. To apply this function with pressure, you use pressure_list = DataModel.GetObjectsByType(DataModelObjectCategory.Pressure).

  • Active Objects. Inserts active_objects = Tree.ActiveObjects, providing a list of all selected objects in the tree.

  • FirstActiveObject. Inserts first_active_object = 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 = 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]')] 

  • Selection Manager. Inserts selection_manager = ExtAPI.SelectionManager, providing access to the Selection Manager. This object contains properties and functions related to graphical selection within Mechanical, such as getting information about the current selection or modifying the selection.

  • Model View Manager. Inserts model_view_manager Graphics.ModelViewManager, providing access to the Model View Manager. This object provides functionality to control managed graphical views.

Lastly, the folder Examples provides snippets that you can use as templates. For example, the snippet Add Pressure shows how to create a pressure on the first face of the first body of the first part.