Skip to content

Instantly share code, notes, and snippets.

@hannesdelbeke
Last active August 11, 2022 19:41
Show Gist options
  • Save hannesdelbeke/0c6a5f3dbd0d1896edbe89dc68c91856 to your computer and use it in GitHub Desktop.
Save hannesdelbeke/0c6a5f3dbd0d1896edbe89dc68c91856 to your computer and use it in GitHub Desktop.
blender asset tracer snippets
# get data block from in a blend file.
import blender_asset_tracer.blendfile
blend_file = blender_asset_tracer.blendfile.BlendFile(file_path)
# print(blend_file.blocks)
objs = blend_file.find_blocks_from_code(b'OB')
print(objs)
# since there is no docs of accepted keys, printing some keys here
print(blend_file.code_index.keys())
#[b'REND', b'TEST', b'GLOB', b'WM', b'DATA', b'WS', b'SN', b'SC', b'BR', b'PL', b'OB', b'ME', b'AR', b'MA', b'IM', b'DNA1'])
# WM = window manager
# OB = object
# not BAT, just normal blender python snippet
import bpy
# print undocumented bits
with bpy.data.libraries.load(str(file_path)) as (data_from, data_to):
print(dir(data_from))
# ['Hair Curves', 'actions', 'armatures', 'brushes', 'cache_files', 'cameras', 'collections',
# 'curves', 'fonts', 'grease_pencils', 'images', 'lattices', 'lightprobes', 'lights', 'linestyles',
# 'masks', 'materials', 'meshes', 'metaballs', 'movieclips', 'node_groups', 'objects', 'paint_curves',
# 'palettes', 'particles', 'pointclouds', 'scenes', 'screens', 'simulations', 'sounds', 'speakers',
# 'texts', 'textures', 'volumes', 'workspaces', 'worlds']
# print data in a blend file
import blender_asset_tracer.blendfile
blend_file = blender_asset_tracer.blendfile.BlendFile(file_path)
def get_id_name(block):
name = block[b'id', b'name'].decode()
return name
bf = blendfile.open_blend(file_path)
objects = bf.find_blocks_from_code(b'OB')
print(objects)
print(file_path, [get_id_name(o) for o in objects])
# raise NotImplementedError()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment