fix missing camera collection when importing

This commit is contained in:
pullusb 2025-05-26 15:46:06 +02:00
parent 6d64d6df7f
commit 365bd93408
2 changed files with 16 additions and 9 deletions

View File

@ -4,7 +4,7 @@ bl_info = {
"name": "Background plane manager", "name": "Background plane manager",
"description": "Manage the background image planes and grease pencil object relative to a camera", "description": "Manage the background image planes and grease pencil object relative to a camera",
"author": "Samuel Bernou", "author": "Samuel Bernou",
"version": (0, 5, 3), "version": (0, 5, 4),
"blender": (3, 5, 0), "blender": (3, 5, 0),
"location": "View3D", "location": "View3D",
"warning": "", "warning": "",

23
core.py
View File

@ -296,28 +296,35 @@ def set_collection(ob, collection, unlink=True) :
# check if collection exist or create it # check if collection exist or create it
for c in bpy.data.collections : for c in bpy.data.collections :
if c.name == collection : col = c if c.name == collection :
col = c
if not col : if not col :
col = bpy.data.collections.new(name=collection) col = bpy.data.collections.new(name=collection)
# link the collection to the scene's collection if necessary # link the collection to the scene's collection if necessary
# for c in scn.collection.children : for c in scn.collection.children :
# if c.name == col.name : visible = True if c.name == col.name :
# if not visible : scn.collection.children.link(col) visible = True
if not visible :
scn.collection.children.link(col)
# check if the object is already in the collection and link it if necessary # check if the object is already in the collection and link it if necessary
for o in col.objects : for o in col.objects :
if o == ob : linked = True if o == ob :
if not linked : col.objects.link(ob) linked = True
if not linked :
col.objects.link(ob)
# remove object from scene's collection # remove object from scene's collection
for o in scn.collection.objects : for o in scn.collection.objects :
if o == ob : scn.collection.objects.unlink(ob) if o == ob :
scn.collection.objects.unlink(ob)
# if unlink flag we remove the object from other collections # if unlink flag we remove the object from other collections
if unlink : if unlink :
for c in ob.users_collection : for c in ob.users_collection :
if c.name != collection : c.objects.unlink(ob) if c.name != collection :
c.objects.unlink(ob)
return col return col