Hello in this code below i create a lot of collection and add backups inside of them, its kind of a cool within the file backup system i wrote for my new save management add-on
import bpy
import os
import datetime
#shortcuts
context = bpy.context
scene = context.scene
A = context.object
S = bpy.context.selected_objects
#Date name and .blend name
time = datetime.datetime.now()
date= time.strftime("__%Y-%m-%d_%HH%MM%S")
datecol= time.strftime("%m-%d_%HH%MM%S")
blend = bpy.path.basename(bpy.data.filepath)[:-6]
#Collection Copies
def find_collection(context, item):
collections = item.users_collection
if len(collections) > 0:
return collections[0]
return context.scene.collection
def make_collection(collection_name, parent_collection):
if collection_name in bpy.data.collections:
return bpy.data.collections[collection_name]
else:
new_collection = bpy.data.collections.new(collection_name)
parent_collection.children.link(new_collection)
return new_collection
name = "Copies"
#Collection Date
def make_collection(collection_namme, parent_collection):
if collection_namme in bpy.data.collections:
return bpy.data.collections[collection_namme]
else:
new_collection = bpy.data.collections.new(collection_namme)
parent_collection.children.link(new_collection)
return new_collection
namme = datecol
#Dupplicate selection and move it to scene master collection
bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'})
bpy.ops.object.move_to_collection(collection_index=0)
#move every object to new collection
for C in bpy.context.selected_objects:
C.name = C.name + " Copy"
C_collection = find_collection(bpy.context, C)
new_collection = make_collection(name , C_collection)
new_collection.objects.link(C)
C_collection.objects.unlink(C)
bpy.data.collections["Copies"].hide_select = True
bpy.data.collections["Copies"].hide_render = True
bpy.data.collections["Copies"].hide_viewport = True
C_collection = find_collection(bpy.context, C)
new_collection = make_collection(namme , C_collection)
new_collection.objects.link(C)
C_collection.objects.unlink(C)
bpy.data.collections[datecol].hide_select = True
bpy.data.collections[datecol].hide_render = True
bpy.data.collections[datecol].hide_viewport = True
bpy.context.view_layer.objects.active = A
for ob in S:
ob.select_set(state=True)
the only problem is that it create a lot of collection and i can’t “close” them, they stay enter and take all the space in the outliner, i just want to automate this
the code seems to be eclusive to context.outliner, i can’t even find it
do anyone know how to do this ? is there some examples anywhere ?