PyMechanical scripting API stubs.
Project description
Overview
PyMechanical Stubs generates __init__.py files from assembly files in the Mechanical application to create python files that can be used for autocomplete with PyMechanical. Stubs are generated for each version of Mechanical, starting with 2024 R1.
clr-stubs generate Python stubs for .NET assemblies using pythonnet. These stubs are intended to be used by the autocomplete engine of editors like Atom, Sublime, and VS Code, as well as for python documentation generation (for example, with Sphinx)
Why clr-stubs?
If you are writing python code using .NET modules via pythonnet’s clr.AddReference, your IDE’s autocomplete (which usually runs python) will not be able to follow any .NET namespaces or libraries.
The workaround in clr-stubs is to create ‘stubs’ or ‘fakes’ with the same namespaces, types, and metadata that would typically be available in a pure python library. The ‘stubs’ can then be used by your IDE’s autocomplete.
Manually create __init__.py files
Install Mechanical 2024 R1.
Note
Ensure the environment variable, AWP_ROOTDV_DEV, is set to the location of Mechanical 2024 R1 (C:\Program Files\Ansys Inc\v241).
Clone the repository.
git clone https://github.com/ansys/pymechanical-stubs.git
Run stub_generator/create_files.py to generate the stubs from Mechanical 2024 R1.
python stub_generator/create_files.py
Note
There may be an Unhandled Exception when the stubs are done running. If the message, “Done creating all Mechanical stubs” appears, proceed to the next step.
Next, create and activate a virtual environment:
python -m venv .venv
Windows:
.venv\Scripts\activate.bat
Linux:
source .venv/bin/activate
Install ansys-mechanical-stubs
pip install -e .
Make the Sphinx documentation
make -C doc html
Note
You can ignore any current warning messages. It is a lengthy process to generate the documentation.
Installation
You can use pip to install PyMechanical Stubs.
pip install ansys-mechanical-stubs
To install the latest development version, run these commands:
git clone https://github.com/ansys/pymechanical-stubs
cd pymechanical-stubs
pip install -e .
Install in offline mode
If you lack an internet connection or you do not have access to the private Ansys PyPI packages repository, you should install PyMechanical Stubs by downloading the wheelhouse archive for your corresponding machine architecture from the repository’s Releases page.
Each wheelhouse archive contains all of the Python wheels necessary to install PyMechanical Stubs from scratch on Windows, Linux, and MacOS from Python 3.10 to 3.12. In addition, you can install the wheelhouse on a new virtual environment that does not include any previously installed dependencies.
For example, on Linux with Python 3.10, unzip the wheelhouse archive and install it with these commands:
unzip ansys-mechanical-stubs-v0.1.0-wheelhouse-ubuntu-latest-3.10 -d wheelhouse
pip install ansys-mechanical-stubs -f wheelhouse --no-index --upgrade --ignore-installed
If you are on Windows with Python 3.10, unzip the wheelhouse archive to a wheelhouse directory and then install using the same pip install command as in the preceding example.
Note
If desired, you can install the wheelhouse on an isolated or virtual system. See Creation of virtual environments in the Python documentation for the required steps.
Basic usage
This code shows how to import PyMechanical Stubs and its basic capabilities:
from typing import TYPE_CHECKING
import ansys.mechanical.core as mech
if TYPE_CHECKING:
import ansys.mechanical.stubs.v241.Ansys as Ansys
geometry_import = Model.GeometryImportGroup.AddGeometryImport()
# Lines that start with "Ansys." will autocomplete as you type
geometry_import_format = (
Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic
)
geometry_import_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences()
Documentation and issues
Documentation for the latest stable release of PyMechanical Stubs is hosted at PyMechanical Stubs 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.
On the PyMechanical Stubs Issues page, you can create issues to report bugs and request new features. On the PyMechanical Stubs Discussions page or the Discussions page on the Ansys Developer portal, you can post questions, share ideas, and get community feedback.
To reach the project support team, email pyansys.core@ansys.com.
Credits
This project is inspired by [ironpython-stubs](https://github.com/gtalarico/ironpython-stubs) but is developed from scratch.
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
Built Distribution
Hashes for ansys_mechanical_stubs-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a52f8e4d6032d8ca3ec50665634aec9b0fa7ee23a35707a705d49578ca45e18 |
|
MD5 | 502a12665d28b95d7ddaf3ba13c5f0fc |
|
BLAKE2b-256 | b4d6dd8d2c1d311b8175747ae6147bcab9e44fe92d82ec2e353d8a3c1f20beb7 |
Hashes for ansys_mechanical_stubs-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1cc18c8ab7316148cd8b477828ed758a36e18c8e6000c5bb09f11a4b8ac48fc |
|
MD5 | e8472570ab12938e08b84ff87f9a2b8d |
|
BLAKE2b-256 | 47918bdfae13111e24f11e7cfc318bea7d94c83939346308278d99d4386c78eb |