Note
Go to the end to download the full example code.
Test variable and function scope#
This example calls the run_python_script
method and checks the variable and
function scope between calls.
Launch mechanical#
Launch a new Mechanical session in batch, setting the cleanup_on_exit
argument to False
. To close this Mechanical session when finished,
this example must call the mechanical.exit()
method.
from ansys.mechanical.core import launch_mechanical
mechanical = launch_mechanical(batch=True, cleanup_on_exit=False)
print(mechanical)
Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:242
Software build date: 06/03/2024 09:35:09
Run script to set variable#
Run the script to assign a value to a variable.
x = 10
Access the variable in the next call#
Run the script to change the variable value.
x = 20
Define function#
Run the script to define a function and access the variable defined in the previous call.
output = 200
Access the function#
Run the script to access the function defined in the previous call.
output = 400
Close mechanical#
Close the mechanical instance.
mechanical.exit()
Total running time of the script: (0 minutes 0.180 seconds)