The question is simple enough, but I can't find the answer. Is there an operator or something similar that clears the Blender System Console history? I would also be willing to create an operator type script to "purge" the console. It would be interesting to see if it's possible, or I'm just "delirious". Restarting blender doesn't take long, but it would be nice to have a "Button" to do this.
3 Answers
Below is an example add-on that adds a button to the text editor for this purpose. Clearing the console is done with the platform specific commands cls for Windows and clear for Linux and macOS. Both are executed through os.system(command)
bl_info = {
"name": "Clear System Console",
"author": "Robert Guetzkow",
"version": (1, 0, 0),
"blender": (2, 81, 0),
"location": "Text Editor Header",
"description": "Clear the system console.",
"wiki_url": "",
"category": "Text Editor"}
import bpy
import os
class CLEARCONSOLE_OT_clear(bpy.types.Operator):
bl_idname = "clearconsole.clear"
bl_label = "Clear System Console"
bl_description = "This operator clears the system console."
bl_options = {"REGISTER"}
def execute(self, context):
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
return {"FINISHED"}
def draw(self, context):
self.layout.operator(CLEARCONSOLE_OT_clear.bl_idname)
classes = (CLEARCONSOLE_OT_clear,)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.TEXT_HT_header.append(draw)
def unregister():
bpy.types.TEXT_HT_header.remove(draw)
for cls in classes:
bpy.utils.unregister_class(cls)
if name == "main":
register()
- 25,622
- 3
- 47
- 78
-
I hadn't thought of other operating systems, as I use it on Windows, and I wanted to create a tools that simplifies my programming life a little. All clear, this answer did what I was looking for and more – Noob Cat Aug 07 '20 at 23:59
You can use os.system and call cls or clear:
os.system('cls')os.system('clear')
sort of snippet:
from os import system
cls = lambda: system('cls')
cls() #this function call will clear the console
- 7,821
- 2
- 18
- 37
-
1
-
Sorry, didn't see your answer until I was done implementing mine. – Robert Gützkow Aug 08 '20 at 00:14
-
@RobertGützkow That's a nice spinet which should be archived at north pole! – HikariTW Aug 08 '20 at 00:20
As of 2021, there is an operator for this.
- Clear command history only:
bpy.ops.console.clear(scrollback=False, history=True)
- Clear command history and scrollback history:
bpy.ops.console.clear(history=True)
- Clear scrollback history only:
bpy.ops.console.clear()
Reference: Blender's source code here.
- 171
- 1
- 2

\n\tand other text control stuff, where\fstand for form feed to indicate output go on next page. Which is not clear console for sure – HikariTW Aug 07 '20 at 23:37