To search or to open text blocks in blend files in text editors (as a couple of examples) it would be handy to read texts from a blend file without any need of blender or bpy
.
There is a module for blend file io shipped with blender addons_contrib/io_blend_utils/blend/blendfile.py
I am using blender 2.8. The tools have been added to addons_contrib (come with blender) as of July 4
Re blender 2.79. I imagine that script to read text lines from datablocks using either would be similar and put me on the right track.
The walker script gives insights on how to read the blocks.
Test script below lists the textblock name, and how many characters are on each line. I'm sure there's a simple way to get the body string of the TextLine
data block, but it escapes me.
from io_blend_utils.blend import blendfile
def get_id_name(block):
name = block[b'id', b'name'].decode()
return name[2:]
filepath = "/home/batfinger/Desktop/test.blend"
bf = blendfile.open_blend(filepath)
texts = bf.find_blocks_from_code(b'TX')
for t in texts:
i = s = bf.blocks.index(t) + 1
print(get_id_name(t))
while bf.blocks[i].dna_type_name == 'TextLine':
print(f"line {i - s} chars {bf.blocks[i][b'len']}")
i += 1
How do I read the data to give me the text buffer of a text block?
CRUD EDIT.
Thankyou to @lemon re the Reading piece of the crud puzzle.
As an addendum, would very much appreciate any details on usage of the blendfile
api for:
Creating, Updating and Deleting text blocks.
blendfile.py
$\endgroup$ – batFINGER Feb 27 '20 at 15:08