3

I feel like this should be easier to find. Aug '19, I've searched google and stack with no easy answers.

In Blender 2.8:

I'm looking for the code similar to Print("MY_MESSAGE") into the Info window. Obviously it's easy to use Print('...') into the System Console - sys console unrelated to this question.

I'm looking for any sample code I can literally copy paste into my Blender Text Editor window and run with results.

tldr: one-liner print shit to Info window, pls how?!

  • 1
    Here you go: https://blender.stackexchange.com/questions/717/is-it-possible-to-print-to-the-report-window-in-the-info-view – person132 Aug 27 '19 at 04:23
  • That's like the first thing off google for this question. Not sure if 2.8, or because I don't understand how to correctly use that code, or other reasons, but it does not work for me – fat_flying_pigs Aug 27 '19 at 04:31
  • Again, for what seems (to me) to be a very basic question - in hack-y script-kiddie code - there seems to be a lack of an easily implemented answer that can be quickly found. I'm looking for a copy-pasta hello world. – fat_flying_pigs Aug 27 '19 at 04:35
  • Check https://docs.blender.org/api/blender_python_api_current/bpy.types.Operator.html to see how the operator must be called. – eric.m Aug 27 '19 at 07:41

1 Answers1

3

For all the lazy people, who don't like reading the API on how to register and call an operator:

import bpy

class RENDER_OT_test(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "render.custom_test"
    bl_label = "Test"

    def execute(self, context):
        self.report({'INFO'}, 'Printing report to Info window.')
        return {'FINISHED'}

def register():
    bpy.utils.register_class(RENDER_OT_test)

def unregister():
    bpy.utils.unregister_class(RENDER_OT_test)

if __name__ == "__main__":
    register()

Run the script, press F3 to open up the search menu, type Testand press Enter.

No additional link to prevent lazy people from getting even more lazy.

brockmann
  • 12,613
  • 4
  • 50
  • 93
  • Thank you for this reply! This works for me. The bit that really helped was the F3 -> Test -> Enter, since I am new to Blender. This still seems far more complex than the simple Print(...) statement I hoped for – fat_flying_pigs Aug 27 '19 at 23:08
  • It also appears that this must be run via the F3... combo in order for the info message to appear. I can't seem to make this work from purely from code, when using the Run Script button or alt+p hotkey. – fat_flying_pigs Aug 27 '19 at 23:12
  • 1
    Correct, that is by design. The message intentionally only appears when the user is calling something from within the UI (Search Menu, Button, Part of another operator call and whatnot). If that's too complex for your case, use a print("fat flying pigs") @fat_flying_pigs. However, in case you'd like to build an Add-on, using operators is the way to go anyway. Read: How to create a custom UI?. – brockmann Aug 28 '19 at 09:08
  • 1
    I knew blender was bad, like "pressing b in file select literally opens a bounding box" bad, but I never knew it was "you literally can't print to the designated console" bad – Andy Ray Mar 10 '20 at 02:16
  • 1
    You can print() to the console @AndyRay Question is about how to print into the Info Area... – brockmann Mar 10 '20 at 08:50