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_arg
str,optional One or more inline APDL commands, separated by newlines, or
"-"to read the commands from stdin. WhenNoneand no other source is given, stdin is read as long as it is a pipe carrying data.- commandssequence
ofstr, 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_file
str,optional Path to an APDL script file whose content is sent to MAPDL.
- port
int,optional gRPC port of the running MAPDL instance. Defaults to
50052, or to thePYMAPDL_PORTenvironment variable when it is set.- ip
str,optional IP address of the running MAPDL instance. Defaults to
"127.0.0.1", or to thePYMAPDL_IPenvironment 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.
- timeout
int, default: 10 Seconds to wait when establishing the gRPC connection.
- input_arg
- Returns:
strOutput returned by MAPDL. Can be empty.
- Raises:
ValueErrorWhen no command source or more than one command source is given, or when the resolved command block is empty.
MapdlConnectionErrorWhen no MAPDL instance can be reached at the given address.
MapdlRuntimeErrorWhen MAPDL fails while running the commands.
- Return type:
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"]))