exec_commands#

ansys.mapdl.core.cli.exec.exec_commands(input_arg=None, commands=(), script_file=None, port=None, ip=None, clear_on_connect=False, timeout=10)#

Send APDL commands to a running MAPDL instance and return its output.

Exactly one command source must be given: input_arg, commands, script_file, or stdin.

Parameters:
input_argstr, optional

One or more inline APDL commands, separated by newlines, or "-" to read the commands from stdin. When None and no other source is given, stdin is read as long as it is a pipe carrying data.

commandssequence of str, default: ()

APDL commands. Each item may itself hold several commands separated by newlines. All items are joined with newlines and sent as a single block.

script_filestr, optional

Path to an APDL script file whose content is sent to MAPDL.

portint, optional

gRPC port of the running MAPDL instance. Defaults to 50052, or to the PYMAPDL_PORT environment variable when it is set.

ipstr, optional

IP address of the running MAPDL instance. Defaults to "127.0.0.1", or to the PYMAPDL_IP environment variable when it is set.

clear_on_connectbool, default: False

Whether to clear the MAPDL database upon connecting. Off by default so that successive calls share the same model state.

timeoutint, default: 10

Seconds to wait when establishing the gRPC connection.

Returns:
str

Output returned by MAPDL. Can be empty.

Raises:
ValueError

When no command source or more than one command source is given, or when the resolved command block is empty.

MapdlConnectionError

When no MAPDL instance can be reached at the given address.

MapdlRuntimeError

When MAPDL fails while running the commands.

Return type:

str

Examples

Send two commands to the instance running on the default port:

>>> from ansys.mapdl.core.cli.exec import exec_commands
>>> print(exec_commands(commands=["/prep7", "BLOCK,0,1,0,1,0,1"]))