Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVilém Duha <vilda.novak@gmail.com>2020-04-23 00:55:23 +0300
committerVilém Duha <vilda.novak@gmail.com>2020-05-07 15:19:51 +0300
commit20760ae61e35f9fdcfdd9e15322349e2ce1fd91e (patch)
treea0e01dd3299d77e47ad016803e352dc570491af1
parentb5faa814dc34dfae45f31e9ab8ab44ff8a450071 (diff)
BlenderKit: fix bring to scene
-rw-r--r--blenderkit/overrides.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/blenderkit/overrides.py b/blenderkit/overrides.py
index a0c76326..606a19bb 100644
--- a/blenderkit/overrides.py
+++ b/blenderkit/overrides.py
@@ -187,18 +187,18 @@ class BringToScene(Operator):
return bpy.context.view_layer.objects.active is not None
def execute(self, context):
- import bpy
s = bpy.context.scene
sobs = s.collection.all_objects
aob = bpy.context.active_object
dg = aob.instance_collection
- instances = []
+ vlayer = bpy.context.view_layer
+ instances_emptys = []
# first, find instances of this collection in the scene
for ob in sobs:
- if ob.instance_collection == dg and ob not in instances:
- instances.append(ob)
+ if ob.instance_collection == dg and ob not in instances_emptys:
+ instances_emptys.append(ob)
ob.instance_collection = None
ob.instance_type = 'NONE'
# dg.make_local
@@ -208,21 +208,28 @@ class BringToScene(Operator):
dg.objects.unlink(ob)
try:
s.collection.objects.link(ob)
-
+ ob.select_set(True)
+ obs.append(ob)
if ob.parent == None:
parent = ob
bpy.context.view_layer.objects.active = parent
except Exception as e:
print(e)
- ob.select_set(True)
- obs.append(ob)
+
bpy.ops.object.make_local(type='ALL')
- for ob in obs:
- ob.select_set(True)
+
+ for i, ob in enumerate(obs):
+ if ob.name in vlayer.objects:
+ obs[i] = vlayer.objects[ob.name]
+ try:
+ ob.select_set(True)
+ except Exception as e:
+ print('failed to select an object from the collection, getting a replacement.')
+ print(e)
related = []
- for i, ob in enumerate(instances):
+ for i, ob in enumerate(instances_emptys):
if i > 0:
bpy.ops.object.duplicate(linked=True)