Skip to main content

A python wrapper for Ansys Mechanical

Project description

PyAnsys Python PyPI GH-CI Codecov MIT Black

Overview

PyMechanical 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 session

  • Embed an instance of Mechanical directly as a Python object

Install the package

Install PyMechanical using pip with:

pip install ansys-mechanical-core

For more details, see PyMechanical - Install the package

Dependencies

You must have a licensed copy of Ansys Mechanical installed. 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 started

PyMechanical uses the built-in scripting capabilities of Mechanical. For information on the scripting APIs available, see the Scripting in Mechanical Guide in the Ansys Help.

Configuring the Mechanical installation

On a Windows system, the environment variable AWP_ROOT<ver> is configured when Mechanical is installed, where <ver> is the Mechanical release number, such as 231 for 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 the AWP_ROOT<ver> environment variable to point to the absolute path of a Mechanical installation.

Starting a remote session

To start a remote session of Mechanical on your computer from Python, use the launch_mechanical() method. This methods returns an object representing the connection to the session:

import ansys.mechanical.core as pymechanical

mechanical = pymechanical.launch_mechanical()

Running commands on the remote session

Given 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 object

PyMechanical 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 it will be supported on Linux for version 2023 R2 and later. Here is an example:

import ansys.mechanical.core as pymechanical

app = pymechanical.App()
result = app.ExtAPI.DataModel.Project.ProjectDirectory

Testing and Development

If you would like to test or contribute to the development of PyMechanical, please visit PyMechanical - Contributing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ansys_mechanical_core-0.9.2.tar.gz (50.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ansys_mechanical_core-0.9.2-py3-none-any.whl (57.8 kB view details)

Uploaded Python 3

File details

Details for the file ansys_mechanical_core-0.9.2.tar.gz.

File metadata

  • Download URL: ansys_mechanical_core-0.9.2.tar.gz
  • Upload date:
  • Size: 50.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for ansys_mechanical_core-0.9.2.tar.gz
Algorithm Hash digest
SHA256 3f74d2e63ab132f6779ffc1b76280eb199a5e8bb7bc18fe97e4cfa55cbacdf0d
MD5 440b534bc831d40f97f9b1f911e87312
BLAKE2b-256 00c080ad76c17b30e2868bfa86ec430722df0a05b0ef20c6549337955e76d876

See more details on using hashes here.

File details

Details for the file ansys_mechanical_core-0.9.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ansys_mechanical_core-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 92f34cef32a1233050faa1740f1f45118225adb9cc9db46bd3e31d6d7bd9bbbf
MD5 b188a561acb7164c19364100c98ef708
BLAKE2b-256 314f5d3c3af649f677c192a17d299636ae5c8f996f1bde4e5ad3deecfe27b7bc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page