41
$\begingroup$

I'm trying to debug a Python script by placing a print("foo=" + foo) statement in my code.

But where does the output appear?

It doesn't appear on the Python Console, and it doesn't appear on the area that appears when you drag the lower edge of the infobar downwards (what is the name for this area? My script errors show up in red here.)

$\endgroup$
46
$\begingroup$

It's printed to the system console. If it's not opened, go to Window > Toggle System Console.

Note that this option is only available on Windows. On other OS, start Blender from a terminal.

See here: http://wiki.blender.org/index.php/Doc:2.6/Manual/Interface/Window_system/Console_window

You may also use this script:
Is there anyway to make blender print errors in the UI?

$\endgroup$
  • 3
    $\begingroup$ ah man, you have even written a script to fix it. One upvote is not enough! $\endgroup$ – P i Jan 11 '14 at 1:55
  • 1
    $\begingroup$ Window > Toggle System Console doesn't exist in Blender 2.77 $\endgroup$ – Andy Ray Apr 22 '16 at 21:33
  • $\begingroup$ Not sure what you mean, it clearly exists on Windows in Blender 2.77: i.stack.imgur.com/NTFd8.png - are you on another OS by any chance? Read the answer again in that case, you need to start Blender in a shell. $\endgroup$ – CoDEmanX Apr 23 '16 at 0:08
  • 1
    $\begingroup$ @user824624: read again, I clearly stated that this option is exclusively available on Windows. On Linux and OS X, you need to start Blender from a shell. $\endgroup$ – CoDEmanX Jun 7 '16 at 10:41
  • 1
    $\begingroup$ Warning! If you open the Console, don't ever close it! It will kill Blender instantly without saving! $\endgroup$ – James Watkins Oct 21 '18 at 17:12
7
$\begingroup$

Sorry if this answer isn't quite to your question, but having to do with the subject:

listen up all mac users, here is something for you:

with my own "getting annoyed" experience and help from the idea of this guy (sambler) I made a simple app for the purpose of opening blender with terminal.

---Please try it, it is easy to install and super handy---

here is the application, if you want it and here...

..is how to use it:

  1. Navigate yourself to blender.app with finder.

enter image description here

  1. Right click on blender and select "Show Package contents".

enter image description here

  1. Download the app and unzip it.

enter image description here

  1. Drag the app into blender's "Contents" folder.

enter image description here

  1. Drag the app to dock and open for the first time.

enter image description here

  1. (optional) Dance around the room and sing about how fortunate you are to have such an app.




Alternatively here is the applescript source: (currently, with plenty of helpful comments)

set myPath to ((path to current application) as string) --find the path to blenderOpen.app
set myPath to ((characters 1 through ((length of myPath) - 1) of myPath) as string) --rip off the last ":"
set charDelete to (last character of myPath) -- rip off the "blenderOpen.app"
repeat until charDelete = ":" -- rip off the "blenderOpen.app"
    set myPath to ((characters 1 through ((length of myPath) - 1) of myPath) as string) -- rip off the "blenderOpen.app"
    set charDelete to (last character of myPath) -- rip off the "blenderOpen.app"
end repeat
set myPath to myPath & "MacOS" --find the blender runtime by appending this path

set myPath to quoted form of the POSIX path of myPath -- convert path so terminal understands
(*
why this little if statement down below?
This if statement is here because if a user
opens terminal and runs some command,
then afterwards runs our script,
we want to use a new window so as not
to interfere with the user.
However, if WE open terminal,
than we want to use the window 
that terminal just made for us.
*)

if testterminal() then
    tell application "Terminal" to do script "cd " & myPath & " && ./blender" -- tell terminal to open new window, and open blender, Voila!!!
else
    tell application "Terminal" to tell front window to do script "cd " & myPath & " && ./blender" -- tell terminal to open blender, in the current window, Voila!!!
end if


return myPath
on testterminal()
    tell application "System Events" to (name of processes) contains "Terminal"
end testterminal

Edit:

I forgot to note this feature before but this app also enables you to open up as many instances of blender as you want at the same time.

$\endgroup$
  • $\begingroup$ Please don't post duplicate answers, kindly link to the other post/answer and if you could tidy this up that would be great, thanks! $\endgroup$ – iKlsR Jul 23 '16 at 14:15
  • $\begingroup$ @iKIsR And how would that be done, do you think i should just delete all in edit and paste a link, i'm sorry about the duplicates, how should i go about tidying this up? and thanks for commenting. $\endgroup$ – Pro Blaster Jul 23 '16 at 16:07
  • $\begingroup$ For one, if you are new to markdown, there is a styleguide help button to the top right of the editing area when you are creating the post. You have some comments about leaving an image once you have the rep (which you now do) so maybe add those. Basically look at any post from a high rep user and try to structure it like that. We prefer self contained answers so links to external sources can be added but it's helpful if that same content is summarized here. $\endgroup$ – iKlsR Jul 23 '16 at 16:12
3
$\begingroup$

I'm currently using Blender 2.78 and I think that the easiest way to see your console logs is to go inside the blender container, exactly like in previous posts. Then go to MacOs folder and run blender script. enter image description here It will open terminal and blender application.

enter image description here

$\endgroup$
2
$\begingroup$

Here is my script which redirects the print() function to all open python console windows.

import bpy
def print(data):
    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(data), type="OUTPUT")       
$\endgroup$
1
$\begingroup$

Updated with the second part to the solution.

When you click "run script," Python errors are reported in the console. Blender API errors, however, are not. If you have Blender API errors before the line where your call to print() happens, then your code never reaches that line. Blender and Python both quietly let this happen without error or warning.

Tick the "register" box in the text editor, save, and click "run script". Your script class should have a bl_label field set to a string. Go to the viewport, press spacebar, and type that string. When it shows up in the results, click it.

Now your Blender API errors will show themselves. Correct your code, and when your print() call is reached, it will print to the system console.

I'm shocked that this doesn't seem to appear anywhere on threads about this yet, especially since differences between types such as BMesh and Mesh render show-stopping API errors like this really easy to make.

$\endgroup$
1
$\begingroup$

If you're on macOS and in a terminal, locate blender.app, then do:

./blender.app/Contents/MacOS/blender

Blender's log messages will now appear in the terminal window from which you started it.

Note that open blender.app does not show you any log messages.

$\endgroup$

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.