Connecting using Python
Before writing the actual program, let us ensure that we have the necessary libraries installed on our machine. Open a console and type:
pip install ansys-mapdl-core
This action will install a package which allows you to connect and remotely run apdl commands using Python language/commands.
Now, open the text editor and create the file run_ansys.py (if you wish, you can name it differently; just remember to end with .py extension and use the same name in the following console commands) and type/paste the following content:
from ansys.mapdl.core import Mapdl mapdl = Mapdl("grpc_machine_address", port=50052) print(mqpdl)
where grpc_machine_address is the network address of the machine running gRPC server. If you are running it locally (same machine), use 127.0.0.1; if in local network, use local ip address. More advanced networking we will cover in different articles.
When the file is in place, open the console, get to the file location (move your current location in the terminal to the file one) and run the command:
python run_ansys.py
what should result in the following output:
Product: ANSYS Mechanical Enterprise
MAPDL Version: RELEASE 20XX RX BUILD XX.X
PyMAPDL Version: Version: X.XX.X
If you get this, you know that you have successfully connected the gRPC server and Python program. That opens many possibilities to automate your work or enable execution in a remote environment.
Now, it is time to learn how to execute apdl commands via Python -- coming soon on totalsym.com. If you have some issues, contact us via emial: [email protected]
Remarks
β Possible errors might be connected to networking issues. We are covering them in different article
β There are a couple more settings in initiating comnection which might be helpful. All of them are covered in API documentation on ansys help articles: API Reference