- Accelerate the preparation of your simulations.
- Combine the expressiveness of general-purpose Python code to control the flow in your input decks with methods that drive the solver.
- Explore proof-of-concept studies or capture knowledge using interactive Jupyter notebooks.
- Tap the solver as the physics engine in your next AI app.
Automation via Mechanical Scripting
Inside Ansys Mechanical, automation requirements can be addressed with Mechanical Scripting. For example, a script that counts the number of bodies in the geometry can be written as:
Automation via PyMechanical
If you are already using Python to automate and coordinate your workflows, you can now leverage PyMechanical as an interface to the Mechanical Scripting Interface. It is important to note that PyMechanical uses Standalone Mechanical, a beta feature that enables you to open a standalone version of Ansys Mechanical. This standalone version operates independently of Ansys whilst offering similar features. The differences are slight, and if you are well versed in the use of Mechanical, you should be able to use the standalone version with ease. Launching Standalone Mechanical is done with the following command:PyMechanical Interfaces
PyMechanical offers two distinct modes for interacting with the Mechanical solver:- Remote session: uses PyMechanical as a client to a remote Mechanical instance.
- Embedded instance: uses PyMechanical to embed an instance of Mechanical directly within Python as a Python object.
Remote Mechanical Sessions
In this mode, Mechanical runs as a server, ready to respond to any clients and PyMechanical acts as a client making API calls behind the scenes. To start a remote session of Mechanical on your local computer from Python, simply use thelaunch_mechanical() method. This creates an instance of the Mechanical class in the background and sends commands to it. The method returns an object representing the connection to the session. This works with interactive mode in Python and allows you to develop scripts in real time, before you run your work as a program (or in batch mode).
batch=False argument on launch_mechanical() method, one can observe the effect of the script:
To manually connect to a local/remote session launched using standalone mechanical, use the Mechanical() method. You can find details about this method in Connecting to a remote session.
Below is the complete code, and results from the body count as above:

Embedded Instances
In this mode, PyMechanical directly embeds a Mechanical instance as a Python object, and a Mechanical object is directly loaded into Python memory. No external instance of Mechanical is running. This embedded instance feature is supported on Windows starting from version 2023 R1, and it is supported on Linux from version 2023 R2. Below is the code to get the body count as before.