Open jorzig1990 opened 1 month ago
Hi @jorzig1990 , Thanks for opening the issue. PyMechanical embedding will not allow to create multiple app in same script.
but if you want to work in a new session then you can use app.new()
which clear current session and create new session of Mechanical ( similar to File->New in Mechanical) . You can use like below. In this case you don't have to start another app or close the one that is created, instead use the one already created.
import ansys.mechanical.core as mech
print()
print("Run 1")
print()
app = mech.App(version=242)
app.update_globals(globals())
print("AnsysVersion:")
print(app)
DataModel = app.DataModel
ExtAPI = app.ExtAPI
Model = app.DataModel.Project.Model
Tree = app.DataModel.Tree
Graphics = app.ExtAPI.Graphics
Materials = DataModel.Project.Model.Materials
print()
print("Run 2")
print()
app.new()
print("AnsysVersion:")
print(app)
DataModel = app.DataModel
ExtAPI = app.ExtAPI
Model = app.DataModel.Project.Model
Tree = app.DataModel.Tree
Graphics = app.ExtAPI.Graphics
Materials = DataModel.Project.Model.Materials
Hi @dipinknair,
Thank you for the support.
Is there a solution to reconnect or restart with the app, if I have lost the license connection or it crashed for some other reason? Your solution works fine as long I don't have a problem with the app itself.
The app created in python which only stays till it crashes. No other way to connect it. You can always save your project ( .mechdb/ .mechdat) in between to make sure you can use that if your workflow crashes.
š Before submitting the issue
š Description of the bug
Hello,
I want to implement following workflow in pymechanical as en embedded instance: launch app embedded exit app embedded launch new app embedded
I need this workflow in a larger script in case an error occurs, such as the loss of a licence, and I need to set up a new connection automatically at a later time.
My poblem is, that I can't close the app completely and get allways an error, if I want to launch a new app.
Under Discussion I found the Topic: How to close app? #475 with following answer:
I tried all these commands, but the error message is always the same:
I am using Visual Studio Code and for the execution of the code:
š Steps to reproduce
I have tested all 3 versions from the answer in the discussion:
Test ExtAPI.Application.Exit()
Output ExtAPI.Application.Exit():
Test app.exit()
Output app.exit():
Test ExtAPI.Application.Close():
Output ExtAPI.Application.Close()
š» Which operating system are you using?
Windows
š Which ANSYS version are you using?
AnsysVersion: Ansys Mechanical [Ansys Mechanical Enterprise] Product Version:242 Software build date: 06/03/2024 14:47:58
Python 3.11.9 Environment completely built with pip
š Which Python version are you using?
3.11
š¦ Installed packages