I have this script for saving collections as separate blend files. But it doesnt work for blender files above blender version 3.6. How can I use this script for blender 4.2? What do I need to change?
import bpy
import os
# folder containing blend files
ip_path = "C:\\Blender Projects\\bridge\\"
ip_fname = "bridge_002.blend"
# target folder
op_path = "C:\\Blender Projects\\bridge\\temp\\"
blendfiles = [ip_fname,]
def clear_cur_colls():
while len(bpy.data.collections) > 0:
bpy.data.collections.remove(bpy.data.collections[0])
override = bpy.context.copy()
override["area.type"] = ['OUTLINER']
override["display_mode"] = ['ORPHAN_DATA']
bpy.ops.outliner.orphans_purge(override)
def get_coll_names(assets_path):
names = []
with bpy.data.libraries.load(assets_path) as (data_from, data_to):
names = [name for name in data_from.collections]
return names
for file in blendfiles:
# prep to make a folder based on blend file name
filepath = os.path.join(ip_path, file)
# make a folder based on blend file name to store new files
if not os.path.isdir(op_path):
os.mkdir(op_path)
# get each object from blend file
colls = get_coll_names(filepath)
for coll in colls:
# clear the current file
clear_cur_colls()
# append the object
bpy.ops.wm.append(filepath=file, directory=str(filepath)+"\\Collection\\", filename=coll)
# save blend file
bpy.ops.wm.save_as_mainfile(filepath=os.path.join(op_path, coll+".blend"))
clear_cur_colls()
bpy.ops.outliner.orphans_purge
need not be overriden ? Have you tried simply runningbpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True)
$\endgroup$