connect_to_instance#

ansys.mapdl.core.cli.helpers.connect_to_instance(ip=None, port=None, clear_on_connect=False, timeout=10)#

Connect to an already running MAPDL instance.

Parameters:
ipstr, optional

IP address of the MAPDL gRPC server. When None, the value of the PYMAPDL_IP environment variable is used, defaulting to "127.0.0.1".

portint, optional

Port of the MAPDL gRPC server. When None, the value of the PYMAPDL_PORT environment variable is used, defaulting to 50052.

clear_on_connectbool, default: False

Whether to clear the MAPDL database upon connecting.

timeoutint, default: 10

Seconds to wait when establishing the gRPC connection.

Returns:
ansys.mapdl.core.mapdl_grpc.MapdlGrpc

Client connected to the running instance.

Raises:
MapdlConnectionError

When no MAPDL instance can be reached at the given address. The underlying error is attached as a note on the exception, and the original traceback is suppressed to keep the failure readable.

Return type:

MapdlGrpc

Examples

Connect to the instance running on the default port:

>>> from ansys.mapdl.core.cli.helpers import connect_to_instance
>>> mapdl = connect_to_instance()