1
$\begingroup$

I think I know how to make a report that contains information from the info window. I think the report is saved in a textblock called ‘recent reports’.

My question. How do I read the textblock, or how do I ‘print’ the textblock, or how do I save a file of ‘recent reports’?

I have read: How do I get the Info window's log text with Python?

How to use the textblock operator in Python

https://blenderartists.org/t/copy-from-info-panel/700032/2

$\endgroup$
  • $\begingroup$ Do you want a script that simply saves the contents of the INFO window to a file? $\endgroup$ – rob Aug 7 at 8:01
  • $\begingroup$ @rob Yes I want a script that simply saves the contents of the INFO window to a file. Even better, I would like a file that contained all the current settings to a file. I want to try different settings in Blender and have a readable record of the settings that were used. $\endgroup$ – Paul St George Aug 7 at 9:38
3
$\begingroup$

Recent Reports

Modifying code from https://blender.stackexchange.com/a/62620/15543

The code in answer prints the textblock.

This one removes all other recent reports from blend file, creates a new one via operator, and writes it to filepath

import bpy


#remove other Recent Reports
reports = [bpy.data.texts.remove(t, do_unlink=True) 
           for t in bpy.data.texts
           if t.name.startswith("Recent Reports")]
# make a report
bpy.ops.ui.reports_to_textblock()
# save the report to file

filepath = "recent_reports.txt"
with open(filepath, "a") as f:
    f.write(bpy.data.texts["Recent Reports"].as_string()) 

Alternatively, if you don't want to clean up others, the new text added by operator can be found using sets.

import bpy

texts = set(bpy.data.texts)
bpy.ops.ui.reports_to_textblock()
new_text = (set(bpy.data.texts) - texts).pop()
filepath = "recent_reports.txt"
with open(filepath, "a") as f:
    f.write(new_text.as_string())

both write to a file "recent_reports.txt" in the same folder blender was opened

$\endgroup$
  • $\begingroup$ That works for me up until # save the report to file. The f-string needs Python 3.6 Blender 2.79 comes with Python 3.5 so I need the code without the f. Please. $\endgroup$ – Paul St George Aug 7 at 9:30
  • $\begingroup$ do you get an error or can not find the resulting file? $\endgroup$ – rob Aug 7 at 9:32
  • 1
    $\begingroup$ @PaulStGeorge I get a file named "recent_reports.txt" in the folder I started blender. I have write permission to that folder. Edit filepath to a folder that you can write to. What f-string? Surely with open(...) as f: predates 3.5... anyway it is just simple text file io. Change to suit your python version if need-be. $\endgroup$ – batFINGER Aug 7 at 9:52
  • $\begingroup$ ... oh and don't edit the filepath using f-string formatting. $\endgroup$ – batFINGER Aug 7 at 10:04
  • 1
    $\begingroup$ Now I have done this: 'Edit filepath to a folder that you can write to.', it all works perfectly. $\endgroup$ – Paul St George Aug 7 at 14:58

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.