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
$\begingroup$
$\endgroup$
1
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()
-
$\begingroup$ 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 $\endgroup$– Noob CatCommented Aug 7, 2020 at 23:59
$\begingroup$
$\endgroup$
3
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
-
1$\begingroup$ Very clear and simple, it works wonders $\endgroup$– Noob CatCommented Aug 7, 2020 at 23:49
-
$\begingroup$ Sorry, didn't see your answer until I was done implementing mine. $\endgroup$ Commented Aug 8, 2020 at 0:14
-
$\begingroup$ @RobertGützkow That's a nice spinet which should be archived at north pole! $\endgroup$– HikariTWCommented Aug 8, 2020 at 0:20
$\begingroup$
$\endgroup$
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.
\n
\t
and other text control stuff, where\f
stand for form feed to indicate output go on next page. Which is not clear console for sure $\endgroup$