Mapdl.lgwrite(fname='', ext='', kedit='', remove_grpc_extra=True, **kwargs)#

Writes the database command log to a file.


fnamestr, optional

File name and directory path (248 characters maximum, including the characters needed for the directory path). An unspecified directory path defaults to the working directory; in this case, you can use all 248 characters for the file name.

The file name defaults to Jobname.

extstr, optional

Filename extension (eight-character maximum).

keditstr, optional

Flag to suppress nonessential commands:

  • "NONE" - Do not suppress any commands (default).

  • "COMMENT" - Write nonessential commands as comments (starting with !).

  • "REMOVE" - Do not write nonessential commands or comments.

remove_grpc_extrabool, default: True

Remove gRPC related content (like /OUT,anstmp). This will be ignored when MAPDL is not in gRPC mode.


Writes the database command log to a named file. The database command log contains all commands that were used to create the current database. These commands are recorded in the database as they are issued, and saved in the database file (File.DB) whenever the database is saved. The LGWRITE command extracts these commands from the database and writes them to a file. Nonessential commands (for listing, graphics displays, help, etc.) can be excluded from the file by using the Kedit field. The file resulting from LGWRITE can be used as command input to the program. This command is most useful if the session log file (File.LOG), which is normally saved during an interactive session, has been lost or corrupted.

This command is valid in any processor.


Output the database command log to the local directory.

>>> import os
>>> mapdl.prep7()
>>> mapdl.k(1, 0, 0, 0, mute=True)
>>> mapdl.k(2, 2, 0, 0)
>>> filename = os.path.join(os.getcwd(), 'log.txt')
>>> mapdl.lgwrite(filename, kedit='REMOVE')

Print the output from the log file.

>>> with open(filename) as fid:
...     lines = fid.readlines()
>>> print(''.join(lines))