launch_mechanical#
- ansys.mechanical.core.launch_mechanical(exec_file=None, batch=True, loglevel='ERROR', log_file=False, log_mechanical=None, additional_switches=None, additional_envs=None, start_timeout=120, port=None, ip=None, start_instance=None, verbose_mechanical=False, clear_on_connect=False, cleanup_on_exit=True, version=None, keep_connection_alive=True)#
Start Mechanical locally.
- Parameters:
- exec_file
str
,optional
Path for the Mechanical executable file. The default is
None
, in which case the cached location is used. If PyPIM is configured and this parameter is set toNone
, PyPIM launches Mechanical using itsversion
parameter.- batchbool,
optional
Whether to launch Mechanical in batch mode. The default is
True
. WhenFalse
, Mechanical launches in UI mode.- loglevel
str
,optional
Level of messages to print to the console. Options are:
"WARNING"
: Prints only Ansys warning messages."ERROR"
: Prints only Ansys error messages."INFO"
: Prints all Ansys messages.
The default is
WARNING
.- log_filebool,
optional
Whether to copy the messages to a file named
logs.log
, which is located where the Python script is executed. The default isFalse
.- log_mechanical
str
,optional
Path to the output file on the local disk to write every script command to. The default is
None
. However, you might set"log_mechanical='pymechanical_log.txt'"
to write all commands that are sent to Mechanical via PyMechanical to this file. You can then use these commands to run a script within Mechanical without PyMechanical.- additional_switches
list
,optional
Additional switches for Mechanical. The default is
None
.- additional_envs
dictionary
,optional
Dictionary of additional environment variables to pass. The default is
None
.- start_timeout
float
,optional
Maximum allowable time in seconds to connect to the Mechanical server. The default is
120
.- port
int
,optional
Port to launch the Mechanical gRPC server on. The default is
None
, in which case10000
is used. The final port is the first port available after (or including) this port. You can override the default behavior of this parameter with thePYMECHANICAL_PORT=<VALID PORT>
environment variable.- ip
str
,optional
IP address to use only when
start_instance
isFalse
. The default isNone
, in which case"127.0.0.1"
is used. If you provide an IP address,start_instance
is set toFalse
. A host name can be provided as an alternative to an IP address.- start_instancebool,
optional
Whether to launch and connect to a new Mechanical instance. The default is
None
, in which case an attempt is made to connect to an existing Mechanical instance at the givenip
andport
parameters, which have defaults of"127.0.0.1"
and10000
respectively. WhenTrue
, a local instance of Mechanical is launched. You can override the default behavior of this parameter with thePYMECHANICAL_START_INSTANCE=FALSE
environment variable.- verbose_mechanicalbool,
optional
Whether to enable printing of all output when launching and running a Mechanical instance. The default is
False
. This parameter should be set toTrue
for debugging only as output can be tracked within PyMechanical.- clear_on_connectbool,
optional
When
start_instance
isFalse
, whether to clear the environment when connecting to Mechanical. The default isFalse
. WhenTrue
, a fresh environment is provided when you connect to Mechanical.- cleanup_on_exitbool,
optional
Whether to exit Mechanical when Python exits. The default is
True
. WhenFalse
, Mechanical is not exited when the garbage for this Mechanical instance is collected.- version
str
,optional
Mechanical version to run in the three-digit format. For example,
"231"
for 2023 R1. The default isNone
, in which case the server runs the latest installed version. If PyPIM is configured andexce_file=None
, PyPIM launches Mechanical using itsversion
parameter.- keep_connection_alivebool,
optional
Whether to keep the gRPC connection alive by running a background thread and making dummy calls for remote connections. The default is
True
.
- exec_file
- Returns:
ansys.mechanical.core.mechanical.Mechanical
Instance of Mechanical.
- Return type:
Notes
If the environment is configured to use PyPIM and
start_instance=True
, then starting the instance is delegated to PyPIM. In this case, most of the preceding parameters are ignored because the server-side configuration is used.Examples
Launch Mechanical.
>>> from ansys.mechanical.core import launch_mechanical >>> mech = launch_mechanical()
Launch Mechanical using a specified executable file.
>>> exec_file_path = 'C:/Program Files/ANSYS Inc/v231/aisol/bin/win64/AnsysWBU.exe' >>> mech = launch_mechanical(exec_file_path)
Connect to an existing Mechanical instance at IP address
192.168.1.30
on port50001
.>>> mech = launch_mechanical(start_instance=False, ip='192.168.1.30', port=50001)