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, graphics_backend=None, clear_at_start=False, check_parameter_names=True)#
Converts an ANSYS input file to a python PyMAPDL script.
- Parameters:
- filename_in
str Filename of the ansys input file to read in.
- filename_out
str,optional Filename of the python script to write a translation to. Defaults to the
filename_inname ending inpy.- loglevel
str,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_ending
str,optional When None, automatically is
\n.- exec_file
str,optional Specify the location of the ANSYS executable and include it in the converter output
launch_mapdlcall.- 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 tomapdl.k. WhenFalse, it will be converted tomapdl.run('k').- show_logbool,
optional Print the converted commands using a logger (from
loggingPython module).- add_importsbool,
optional If
True, add the linesfrom ansys.mapdl.core import launch_mapdlandmapdl = 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 overridesauto_exit.- comment_solvebool,
optional If
True, it will pythonically comment the lines that contain"SOLVE"or"/EOF".- cleanup_outputbool,
optional If
Truethe output is formatted usingautopep8before writing the file or returning the string. This requiresautopep8to 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
/COMarguments to python console. Defaults toTrue.- 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). Overridesheader,add_importsandauto_exit.- graphics_backend
GraphicsBackend,optional It sets the mapdl.graphics_backend argument equals True or False depending on this value.
- clear_at_startbool,
optional Add a mapdl.clear() after the Mapdl object initialization.
- check_parameter_namesbool,
optional Check if parameter names are valid MAPDL parameter names. Defaults to
True.
- filename_in
- Returns:
listList of lines translated.
- Return type:
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])