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_strings
str APDL code to convert.
- loglevel
str, 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_ending
str,optional Line ending of the generated script. When
None,"\n"is used.- exec_file
str,optional Location of the MAPDL executable to include in the generated
launch_mapdlcall.- 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.Mapdlmethods. WhenTrue, the MAPDL commandKbecomesmapdl.k, otherwisemapdl.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_mapdllines 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
/COMarguments 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_backend
strorGraphicsBackend,optional Graphics backend to set on the generated MAPDL object. Accepts a
ansys.mapdl.core.plotting.GraphicsBackendmember or its name, which is case insensitive. WhenNone, theansys.mapdl.core.Mapdldefault 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.
- apdl_strings
- Returns:
strThe converted PyMAPDL code.
- Raises:
ValueErrorWhen graphics_backend does not name a valid graphics backend.
- Return type:
Examples
Convert a small APDL block:
>>> from ansys.mapdl.core.cli.convert import convert >>> print(convert("/prep7", only_commands=True)) mapdl.prep7()