What's New at 2019 R1 Mechanical Enhancements
What's New at 2019 R1 Mechanical Enhancements
May 2021
Scripting in Ansys Mechanical
• Scripting allows the use of programming for interacting directly with Mechanical.
‐ Access and interact with data of Mechanical objects.
‐ Automate routine tasks.
‐ Efficiently perform tasks that typically require significant time and effort.
‐ Create user-friendly User Buttons.
• First step toward developing more advanced customization.
‐ Find, test, develop, and debug commands for creating ACT extensions.
‐ Add capability to the Mechanical menus.
‐ Generate workflows for non-experts.
2
Scripting in Ansys Mechanical
• Console:
‐ Editor:
• For developing long scripts for your workflows.
• Can read in from files, promote to buttons, save, run.
‐ Shell:
• Enter commands to see what they do immediately.
• Aid in testing and development of scripts.
3
Scripting in Ansys Mechanical
4
Scripting in Ansys Mechanical
5
Scripting in Ansys Mechanical
6
Scripting in Ansys Mechanical
• Key features:
‐ Auto-completion of commands.
• Upon entering the “.”, list of available selections appears.
• Start typing or select desired item and <enter> to add to command.
• Ctrl + <up arrow> brings back the previous command.
‐ Text coloration.
‐ Snippets.
• Predefined commands that can be used for later insertion.
• Scripting requirements:
‐ Knowledge of Python.
‐ Lots of practice, trying things, and guesswork.
‐ Scripting examples (many in the Ansys Help).
‐ Scripting class in Ansys Learning Hub.
‐ Use of the new recording feature.
7
Scripting in Ansys Mechanical
8
Scripting in Ansys Mechanical
9
Scripting in Ansys Mechanical
• Recording scripts:
‐ Index based, which is typically not the form one may want.
• Similar to FITEM, P51X picking options in MAPDL log file.
• Great way to find the APIs you need, then can edit to add more general capability.
• Not everything is available via recording.
‐ Example: Insert a Total Deformation Item generates the following:
• Internal Object ID 26 points to the Solution item in this model:
10
Scripting in Ansys Mechanical
11
Scripting in Ansys Mechanical
12
Scripting in Ansys Mechanical
13
Scripting in Ansys Mechanical
14
Scripting in Ansys Mechanical
• Selections.
‐ Get IDs of entities currently selected in UI:
• ExtAPI.SelectionManager.CurrentSelection
‐ Create a new empty selection:
• tempSel = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
‐ Select list of Ids to select:
• tempSel.Ids = [34]
‐ Create a pressure and assign location from selection:
• Pressure = ExtAPI.DataModel.Project.Analysis[0].AddPressure()
• Pressure.Location = tempSel
15
Scripting in Ansys Mechanical
16
Scripting in Ansys Mechanical
17
Scripting in Ansys Mechanical
18
Scripting in Ansys Mechanical
• FixedSupportFaces and InsideFaces are Named Selections that must already exist.
19
Scripting in Ansys Mechanical
20
Scripting in Ansys Mechanical
21