7
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ Try printing a '\f' form feed and see what that does? $\endgroup$ – Ron Jensen Aug 7 at 23:07
  • $\begingroup$ Forgive my ignorance, what should I enter? print ("\ f")? $\endgroup$ – Noob Cat Aug 7 at 23:13
  • $\begingroup$ Do print('\f') with no space. Its a control character like '\n' for newline $\endgroup$ – Ron Jensen Aug 7 at 23:28
  • $\begingroup$ Ok I tried it from a Blender Text script and from Blender's python console. Weird symbols come up, but I don't really understand what this is for. $\endgroup$ – Noob Cat Aug 7 at 23:30
  • $\begingroup$ Just like \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$ – HikariTW Aug 7 at 23:37
9
$\begingroup$

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)

Text Editor Header

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()
| improve this answer | |
$\endgroup$
  • $\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 Cat Aug 7 at 23:59
7
$\begingroup$

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
| improve this answer | |
$\endgroup$
  • $\begingroup$ Very clear and simple, it works wonders $\endgroup$ – Noob Cat Aug 7 at 23:49
  • $\begingroup$ Sorry, didn't see your answer until I was done implementing mine. $\endgroup$ – Robert Gützkow Aug 8 at 0:14
  • $\begingroup$ @RobertGützkow That's a nice spinet which should be archived at north pole! $\endgroup$ – HikariTW Aug 8 at 0:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.