convert_apdl_block#

ansys.mapdl.core.convert_apdl_block(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)#

Converts an ANSYS input string to a python PyMAPDL string.

Parameters:
apdl_stringstr

APDL strings or list of strings to convert.

filename_outstr

Filename of the python script to write a translation to.

loglevelstr, optional

Logging level of the ansys object within the script.

auto_exitbool, optional

Adds a line to the end of the script to exit MAPDL. Default True.

line_endingstr, optional

When None, automatically determined by OS being used.

macros_as_functionsbool, optional

Attempt to convert MAPDL macros to python functions.

use_function_namesbool, optional

Convert MAPDL functions to ansys.mapdl.core.Mapdl class methods. When True, the MAPDL command “K” will be converted to mapdl.k. When False, it will be converted to mapdl.run('k').

show_logbool, optional

Print the converted commands using a logger (from logging Python module).

add_importsbool, optional

If True, it add the next lines to the beginning of the output file:

from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl(loglevel="WARNING")

This option is useful if you are planning to use the output script from another mapdl session. See examples section. This option overrides 'auto_exit'.

comment_solvebool, optional

If True, pythonically comment the lines containing mapdl.solve or "/EOF".

cleanup_outputbool, optional

If True the output is formatted using autopep8 before writing the file or returning the string.

headerbool, optional

If True, the default header is written in the first line of the output. If a string is provided, this string will be used as header.

print_combool, optional

Print command /COM arguments to python console. Defaults to True.

Returns:
list

List of lines translated.

Examples

Convert a script and use it in the same session.

>>> from ansys.mapdl.core import examples, launch_mapdl, convert_apdl_block
>>> in_file = examples.vmfiles['vm10']
>>> filename = in_file.split('\')[-1]
>>> out_file = 'out_' + filename.replace('.dat', '.py')
>>> cmds = convert_apdl_block(file, out_file, line_ending='\n')
>>> # Do any change in the text, for example:
>>> cmds = cmds.replace('solve', '!solve')
>>> mapdl = launch_mapdl()
>>> mapdl.input_strings(cmds.splitlines()[2:10])