B3.2: throwing away the blender console

Hi all :slight_smile:

I gess most of you love the old MS-DOS-like console as a print output.
From my point of view it is almost as bothering as ugly…

  • run your script
  • switch to console
  • scroll the 27000 lines up to see one print among lots of others
  • get back to blender
  • correct what needs to be
  • run your script…
    It is almost as effective as if your computer display screen was in another room :rofl:

Now i just bring you a simplification, a revolution, an apocalypse !!!
Logging your messages IN BLENDER UI !!! :open_mouth:

yes this is possible with some few thousands lines of code…
so, here is the HUGE code !

def LOG(msg:str):
    for window in bpy.context.window_manager.windows:
        screen = window.screen
        for area in screen.areas:
            if area.type == 'CONSOLE':
                override = {'window': window, 'screen': screen, 'area': area}
                bpy.ops.console.scrollback_append(override, text=str(msg), type="OUTPUT")

Note you can replace ‘LOG’ with ‘print’ :stuck_out_tongue: but am not sure python is able to deal with this :confused:

Hope you ̶l̶i̶k̶e̶ venerate it :smiley:

For now it writes in the python console.
If someone can give the way to write in INFO window it will be much better :wink:

Happy blending ! :slight_smile:

6 Likes

That’s really great! If you now can also write us a code which puts the error messages bpy spits out to the console, you will be our hero! :wink: (i know the code of codemanx, but maybe there is already a more elegant way)

1 Like

Hi @Blender_Fun1 :slight_smile:

Sorry, i missed your post :frowning:

I just came here to add a lil thing that unity3D offers in its console: The time of the Log…

I just made a short module for time ( that i will surely grow in the future with some funcs like GetDeltaTime or other things ) and just loaded in my Debug module.

So here are the 2 parts:
Time-tools.py

from datetime import datetime



def GetTime()->datetime:
    return(datetime.now())


def Str(t:datetime)->str:
    return(t.strftime("%H:%M:%S"))

And Debug-tools.py

import bpy


TIM  = bpy.data.texts["Time-tools.py"].as_module()




def Log(msg):
    for window in bpy.context.window_manager.windows:
        screen = window.screen
        for area in screen.areas:
            if area.type == 'CONSOLE':
                override = {'window': window, 'screen': screen, 'area': area}
                bpy.ops.console.scrollback_append(override, text=TIM.Str(TIM.GetTime())+" "+str("".join([str(x) for x in msg])), type="OUTPUT")    
#============================================================================================================================================

The thing is simple as hello but i confess i now don’t use the print function anymore :stuck_out_tongue:

You talk about the console @Blender_Fun1. Don’t you mean the Info window ?
This would also be great to clone the info window output to the python console :smiley:
Also if it’s doable, this would be better to be able to change text colors…

I’m not sure but some moments ago, @iceythe gave me a clue on how to deal with some events in blender. I’m no sure info window content goes through events but if yes, this may help redirecting content to python console…

Happy blending ! :smiley:

EDIT: I found a way with copy and paste ( stupidly passing through the clipboard ) but as lines in python console are interpreted when pasted it messes the display.
This would seem better to go through a text but as devs sometimes make the dumbest choices, it is just simply impossible ( the only usefull function for doing this ave been removed :confused: )
I see no way of doing this totally basic thing…
cruel life… :rage:

1 Like

Okay… got it but i’m a bit ashamed of this sh*tty piece of code :confused:

here it is:

            ooo = AccessWindow('INFO')
            with bpy.context.temp_override(area=ooo['area']):
                bpy.ops.info.select_all(ooo,action='SELECT')
                bpy.ops.info.report_copy(ooo)
                bpy.ops.info.report_delete(ooo)
                
                
            DBG.Log(bpy.context.window_manager.clipboard)

The accesswindow is a function of mine for grabbing window for override:


def AccessWindow(typ:str)->dict:
    
    override = None
    
    for foundArea in bpy.context.screen.areas:
        if foundArea.type == typ:
            for region in foundArea.regions:
                if 'WINDOW' in region.type:
                    override = {'area': foundArea, 'region': region}
                    break
            break
    
    return(override)

beware as this is code with no control at all. It might crash blender !
In any case an info window needs to be opened ( even very small ) for this to work :stuck_out_tongue:

At last but not least, this could ( should ? ) also be a handler bind to the info window on a draw_post event :slight_smile:

Happy blending ! :smiley:

1 Like

Well @Blender_Fun1 , here’s a lil piece of info copier to console:

                       

DBG  = bpy.data.texts["Debug-tools.py"].as_module()




def AccessWindow(typ:str)->dict:
    
    override = None
    
    for foundArea in bpy.context.screen.areas:
        if foundArea.type == typ:
            for region in foundArea.regions:
                if 'WINDOW' in region.type:
                    override = {'area': foundArea, 'region': region}
                    break
            break
    
        #with bpy.context.temp_override(area=foundArea):
        #    bpy.ops.outliner.show_active(override)
    return(override)










def rerouteInfoToConsole():

    ooo = AccessWindow('INFO')
    with bpy.context.temp_override(area=ooo['area']):
        bpy.ops.info.select_all(ooo,action='SELECT')
        bpy.ops.info.report_copy(ooo)
        bpy.ops.info.report_delete(ooo)
        
    print(len(bpy.context.window_manager.clipboard))
    if(len(bpy.context.window_manager.clipboard)==0): return
        
    DBG.Log(bpy.context.window_manager.clipboard)





def register():

    # i dont know how to remove handler..... If someone knows please post here ;-)
    bpy.types.SpaceInfo.draw_handler_add(rerouteInfoToConsole, (), 'WINDOW', 'POST_PIXEL')
    

def unregister():
    print("hopla")


if __name__ == "__main__":
    register()




1 Like

i recommend this addon. it redirects all console prints to the blender python console. tested in 3.2.
note it doesn’t seem to handle warnings and errors (or not consistantly)

here’s a screenshot.
print hello now prints to the python console instead of the system console.
but errors e.g. a typo, still print to sys console.

you can tell where the print hello cam from by color. green(sys console redirect) vs blue

2 Likes