convert_apdl_block#
- ansys.mapdl.core.convert.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, only_commands=False, graphics_backend=None, clear_at_start=False, check_parameter_names=False)#
Converts an ANSYS input string to a python PyMAPDL string.
- Parameters:
- apdl_string
str APDL strings or list of strings to convert.
- 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 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 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, 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 containingmapdl.solveor"/EOF".- cleanup_outputbool,
optional If
Truethe output is formatted usingautopep8before 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
/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_backendbool,
optional It sets the mapdl.graphics_backend argument equals True or False depending on this value. Defaults to None which is Mapdl class default.
- clear_at_startbool,
optional Add a mapdl.clear() after the Mapdl object initialization. Defaults to False.
- check_parameter_namesbool,
optional Set MAPDL object to avoid parameter name checks (do not raise leading underscored parameter exceptions). Defaults to False.
- apdl_string
- Returns:
listList of lines translated.
- Return type:
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])