convert_script#

ansys.mapdl.core.convert.convert_script(filename_in, filename_out=None, 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, use_vtk=None, clear_at_start=False, check_parameter_names=True)#

Converts an ANSYS input file to a python PyMAPDL script.

Parameters:
filename_instr

Filename of the ansys input file to read in.

filename_outstr, optional

Filename of the python script to write a translation to. Defaults to the filename_in name ending in py.

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 is ``

.``
exec_filestr, optional

Specify the location of the ANSYS executable and include it in the converter output launch_mapdl call.

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, add the lines from ansys.mapdl.core import launch_mapdl and mapdl = launch_mapdl(loglevel="WARNING") to the beginning of the output file. 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, it will pythonically comment the lines that contain "SOLVE" or "/EOF".

cleanup_outputbool, optional

If True the output is formatted using autopep8 before writing the file or returning the string. This requires autopep8 to be installed.

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.

only_commandsbool, optional

If True, it converts only the commands, meaning that header (header=False), imports (add_imports=False), and exit commands are NOT included (auto_exit=False). Overrides header, add_imports and auto_exit.

use_vtkbool, optional

It sets the mapdl.use_vtk argument equals True or False depending on this value.

clear_at_startbool, optional

Add a mapdl.clear() after the Mapdl object initialization.

Returns:
list

List of lines translated.

Return type:

List[str]

Examples

>>> from ansys.mapdl import core as pymapdl
>>> from ansys.mapdl.core import examples
>>> clines = pymapdl.convert_script(examples.vmfiles['vm1'], 'vm1.py')

Converting a script and using it already in the same session. For this case, it is recommended to use convert_apdl_block() since you do not need to write the file.

>>> import os
>>> from ansys.mapdl.core import launch_mapdl
>>> from ansys.mapdl.core import examples
>>> from ansys.mapdl.core import convert_script
>>> in_file = examples.vmfiles['vm10']
>>> filename = os.path.basename(in_file)
>>> out_file = 'out_' + filename.replace('.dat', '.py')
>>> output = convert_script(file, out_file, line_ending='\n')
>>> mapdl = launch_mapdl()
>>> with open(out_file, 'r') as fid:
...     cmds = fid.read()
>>> mapdl.input_strings(cmds.splitlines()[2:10])