convert#

ansys.mapdl.core.cli.convert.convert(apdl_strings, loglevel='WARNING', auto_exit=True, line_ending=None, exec_file=None, macros_as_functions=True, use_function_names=True, show_log=False, add_imports=True, comment_solve=False, cleanup_output=True, header=True, print_com=True, only_commands=False, graphics_backend=None, clear_at_start=False, check_parameter_names=False)#

Convert an APDL script to PyMAPDL code.

Parameters:
apdl_stringsstr

APDL code to convert.

loglevelstr, default: “WARNING”

Logging level of the MAPDL object in the generated script.

auto_exitbool, default: True

Whether to add a line at the end of the script to exit MAPDL.

line_endingstr, optional

Line ending of the generated script. When None, "\n" is used.

exec_filestr, optional

Location of the MAPDL executable to include in the generated launch_mapdl call.

macros_as_functionsbool, default: True

Whether to convert MAPDL macros to Python functions.

use_function_namesbool, default: True

Whether to convert MAPDL commands to ansys.mapdl.core.Mapdl methods. When True, the MAPDL command K becomes mapdl.k, otherwise mapdl.run("k").

show_logbool, default: False

Whether to print the converted commands through a logger.

add_importsbool, default: True

Whether to add the import and launch_mapdl lines at the beginning of the generated script. Overrides auto_exit.

comment_solvebool, default: False

Whether to comment out the lines containing "SOLVE" or "/EOF".

cleanup_outputbool, default: True

Whether to format the output with autopep8, which must be installed.

headerbool or str, default: True

When True, the default header is written in the first line of the output. When a string, it is used as the header.

print_combool, default: True

Whether to print /COM arguments to the Python console.

only_commandsbool, default: False

Whether to convert only the commands, without header, imports, or exit commands. Overrides header, add_imports, and auto_exit.

graphics_backendstr or GraphicsBackend, optional

Graphics backend to set on the generated MAPDL object. Accepts a ansys.mapdl.core.plotting.GraphicsBackend member or its name, which is case insensitive. When None, the ansys.mapdl.core.Mapdl default is used.

clear_at_startbool, default: False

Whether to add a mapdl.clear() call after the MAPDL object is created.

check_parameter_namesbool, default: False

Whether the generated MAPDL object checks parameter names, raising an exception on leading underscores.

Returns:
str

The converted PyMAPDL code.

Raises:
ValueError

When graphics_backend does not name a valid graphics backend.

Return type:

str

Examples

Convert a small APDL block:

>>> from ansys.mapdl.core.cli.convert import convert
>>> print(convert("/prep7", only_commands=True))
mapdl.prep7()