Skip to main content
This is a quick-reference guide for PyMechanical. This guide covers two unique methods, you can jump to a section of your choosing by using these links: A. Connect to a remote session of Mechanical form Python: Launch and connect to a session | Launch by version | Launch the Mechanical UI | Send Commands to Mechanical B. Load an embedded instance of Mechanical in Python: Embed a Mechanical Instance

A. Connect to a remote session of Mechanical from Python

Launch and connect to a Session

Launch and connect to Mechanical locally:
Launch Mechanical from a local or remote terminal:
Manually connect to this Mechanical session from a local client:

Launch by Version

Verify the license and version of Mechanical that is used: python print(mechanical) Launch a specific version of Mechanical:

Launch the Mechanical UI

Launch the Mechanical UI:

Send Commands to Mechanical

Run a single command: python result1 = mechanical.run_python_script("2+3") result2 = mechanical.run_python_script("ExtAPI.DataModel.Project.ProjectDirectory") mechanical.run_python_script("Model.AddStaticStructuralAnalysis()") Execute a block of commands:
Execute a Python script file:
Import a Mechanical file and print the count of bodies:
Perform project-specific operations:

B. Load an Embedded Instance of Mechanical in Python

Embed a Mechanical instance

Embed a mechanical instance: ```python from ansys.mechanical.core import App app = App(version=232) print(app)
Access entry points from Python:
Import a file and print the count of bodies:
Turn on warning logging:

References from PyMechanical and Mechanical documentation