def main(): # ---------- # Parse Args args = argparse_create().parse_args() if not args.output: if args.check_file: args.output = [None] * len(args.input) else: args.output = [os.path.splitext(infile)[0] + ".json" for infile in args.input] if args.block_filters: args.block_filters = [(True if m[0] == "+" else False, 0 if len(m) == 1 else (-1 if m[1] == "*" else int(m[1:])), re.compile(f), re.compile(d)) for m, f, d in args.block_filters] for infile, outfile in zip(args.input, args.output): with blendfile.open_blend(infile) as blend: address_map = gen_fake_addresses(args, blend) if args.check_file: check_file(args, blend) if outfile: with open(outfile, 'w', encoding="ascii", errors='xmlcharrefreplace') as f: blend_to_json(args, f, blend, address_map)
def theme_data(userpref_filename): import blendfile blend = blendfile.open_blend(userpref_filename) u = next((c for c in blend.blocks if c.code == b'USER'), None) # theme_type = b.sdna_index_from_id[b'bTheme'] t = u.get_pointer((b'themes', b'first')) t.refine_type(b'bTheme') return blend, t
def query_main_scene(filepath, callbacks): """Return the equivalent to bpy.context.scene""" with blendfile.open_blend(filepath) as blend: # There is no bpy.context.scene, we get it from the main window window_manager = [block for block in blend.blocks if block.code == b'WM'][0] window = window_manager.get_pointer(b'winactive') screen = window.get_pointer(b'screen') scene = screen.get_pointer(b'scene') output = [] for callback in callbacks: output.append(callback(scene)) return output