I am working on a script that makes some changes to a Blender project file (for example, randomising material base colours) and then saves those changes to a new project file. I would like to create several different files from the same 'template'. However when I try to iterate using a for loop to specify how many new files I would like to create, the script throws an AttributeError after the first pass: "'Context' object has no attribute 'selected_objects'."
I believe this is because I'm trying to re-open the original project file to undo all the changes after each pass but I have no idea how to solve the problem
project_path = bpy.path.abspath("//") current_filename = bpy.path.basename(bpy.context.blend_data.filepath) for i in range(10): asset_folder = 'C:\\KabooAssets\\Fruit' new_version(asset_folder) # make new variation of current file # save to new Blender file and reset state of current file bpy.ops.wm.save_as_mainfile( filepath=project_path + 'FruitHammer_' + str(i) + '.blend', copy=True ) bpy.ops.wm.open_mainfile(filepath=project_path + current_filename)