Package: ansys-mechanical-core
OverviewPyMechanical brings Ansys Mechanical to Python. It enables your Python programs to use
Mechanical within Python’s ecosystem. It includes the ability to:Connect to a remote Mechanical sessionEmbed an instance of Mechanical directly as a Python objectInstall the packageInstall PyMechanical usingpipwith:pip install ansys-mechanical-coreFor more information, seeInstall the packagein the PyMechanical documentation.DependenciesYou must have a licensed copy ofAnsys Mechanicalinstalled. When using an embedded instance, that installation must be runnable from the
same computer as your Python program. When using a remote session, a connection to that
session must be reachable from your Python program.Getting startedPyMechanical uses the built-in scripting capabilities of Mechanical. For information on the
scripting APIs available, see theScripting in Mechanical Guidein the
Ansys Help.Configuring the mechanical installationOn a Windows system, the environment variableAWP_ROOT<ver>is configured when Mechanical is
installed, where<ver>is the Mechanical release number, such as231for release 2023 R1.
PyMechanical automatically uses this environment variable (or variables if there are multiple
installations of different versions) to locate the latest Mechanical installation. On a Linux
system, you must configure theAWP_ROOT<ver>environment variable to point to the
absolute path of a Mechanical installation.Starting a remote sessionTo start a remote session of Mechanical on your computer from Python, use thelaunch_mechanical()method. This methods returns an object representing the connection to the session:importansys.mechanical.coreaspymechanicalmechanical=pymechanical.launch_mechanical()Running commands on the remote sessionGiven a connection to a remote session, you can send an IronPython script. This uses the built-in
scripting capabilities of Mechanical. Here is an example:result=mechanical.run_python_script("2+3")result=mechanical.run_python_script("ExtAPI.DataModel.Project.ProjectDirectory")Using an embedded instance of Mechanical as a Python objectPyMechanical also supports directly embedding an instance of Mechanical as a Python object.
In this mode, there is no externally running instance of Mechanical. This feature is supported
on Windows for version 2023 R1 and later, and on Linux for version 2023 R2
and later. Here is an example:importansys.mechanical.coreaspymechanicalapp=pymechanical.App()project_dir=app.ExtAPI.DataModel.Project.ProjectDirectoryDocumentation and issuesDocumentation for the latest stable release of PyMechanical is hosted atPyMechanical documentation.In the upper right corner of the documentation’s title bar, there is an option for switching from
viewing the documentation for the latest stable release to viewing the documentation for the
development version or previously released versions.You can alsoviewordownloadthe
PyMechanical cheat sheet. This one-page reference provides syntax rules and commands
for using PyMechanical.On thePyMechanical Issuespage,
you can create issues to report bugs and request new features. On thePyMechanical Discussionspage or theDiscussionspage on the Ansys Developer portal, you can post questions, share ideas, and get community feedback.To reach the project support team, emailpyansys.core@ansys.com.Testing and developmentIf you would like to test or contribute to the development of PyMechanical, seeContributein
the PyMechanical documentation.