feat: uuid collection editing

This commit is contained in:
Swann
2019-10-08 22:24:58 +02:00
parent 5e1f019f24
commit b5910ca5b4

View File

@ -17,36 +17,51 @@ class BlCollection(BlDatablock):
# link objects # link objects
for object in data["objects"]: for object in data["objects"]:
if object not in target.objects.keys(): object_ref = utils.find_from_attr('uuid',object,bpy.data.objects)
target.objects.link(bpy.data.objects[object]) if object_ref and object_ref.name not in target.objects.keys():
target.objects.link(object_ref)
for object in target.objects.keys(): for object in target.objects:
if object not in data["objects"]: if object.uuid not in data["objects"]:
target.objects.unlink(bpy.data.objects[object]) target.objects.unlink(object)
# Link childrens # Link childrens
for collection in data["children"]: for collection in data["children"]:
if collection not in target.children.keys(): collection_ref = utils.find_from_attr('uuid',collection,bpy.data.collections)
# if bpy.data.collections.find(collection) == -1: if collection_ref and collection_ref.name not in target.children.keys():
target.children.link( target.children.link(collection_ref)
bpy.data.collections[collection])
for collection in target.children.keys(): for collection in target.children:
if collection not in data["children"]: if collection.uuid not in data["children"]:
target.collection.children.unlink( target.collection.children.unlink(collection)
bpy.data.collections[collection])
utils.dump_anything.load(target, data) utils.dump_anything.load(target, data)
def dump(self, pointer=None): def dump(self, pointer=None):
assert(pointer) assert(pointer)
data = {}
data['name'] = pointer.name
dumper = utils.dump_anything.Dumper() # dump objects
dumper.depth = 2 collection_objects = []
dumper.include_filter = ['name','objects', 'children', 'uuid'] for object in pointer.objects:
collection_objects.append(object.uuid)
return dumper.dump(pointer) data['objects'] = collection_objects
# dump children collections
collection_children = []
for object in pointer.objects:
collection_children.append(object.uuid)
data['children'] = collection_objects
# dumper = utils.dump_anything.Dumper()
# dumper.depth = 2
# dumper.include_filter = ['name','objects', 'children']
# return dumper.dump(pointer)
return data
def resolve(self): def resolve(self):
assert(self.data) assert(self.data)
# self.pointer = bpy.data.collections.get(self.data['name']) # self.pointer = bpy.data.collections.get(self.data['name'])