diff options
Diffstat (limited to 'blenderkit/append_link.py')
-rw-r--r-- | blenderkit/append_link.py | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/blenderkit/append_link.py b/blenderkit/append_link.py index 2301daac..5af63fe1 100644 --- a/blenderkit/append_link.py +++ b/blenderkit/append_link.py @@ -189,12 +189,44 @@ def append_particle_system(file_name, obnames=[], location=(0, 0, 0), link=False def append_objects(file_name, obnames=[], location=(0, 0, 0), link=False, **kwargs): '''append objects into scene individually''' + #simplified version of append + scene = bpy.context.scene + sel = utils.selection_get() + bpy.ops.object.select_all(action='DESELECT') + + path = file_name + "\\Collection\\" + object_name = kwargs.get('name') + fc = utils.get_fake_context(bpy.context, area_type='VIEW_3D') + bpy.ops.wm.append(fc,filename=object_name, directory=path) + + + return_obs = [] + for ob in bpy.context.scene.objects: + if ob.select_get(): + return_obs.append(ob) + if not ob.parent: + main_object = ob + ob.location = location + + if kwargs.get('rotation'): + main_object.rotation_euler = kwargs['rotation'] + + if kwargs.get('parent') is not None: + main_object.parent = bpy.data.objects[kwargs['parent']] + main_object.matrix_world.translation = location + + bpy.ops.object.select_all(action='DESELECT') + utils.selection_set(sel) + + return main_object, return_obs with bpy.data.libraries.load(file_name, link=link, relative=True) as (data_from, data_to): sobs = [] - for ob in data_from.objects: - if ob in obnames or obnames == []: - sobs.append(ob) + for col in data_from.collections: + if col == kwargs.get('name'): + for ob in col.objects: + if ob in obnames or obnames == []: + sobs.append(ob) data_to.objects = sobs # data_to.objects = data_from.objects#[name for name in data_from.objects if name.startswith("house")] @@ -221,6 +253,7 @@ def append_objects(file_name, obnames=[], location=(0, 0, 0), link=False, **kwar hidden_objects.append(obj) obj.hide_viewport = False return_obs.append(obj) + # Only after all objects are in scene! Otherwise gets broken relationships if link == True: bpy.ops.object.make_local(type='SELECT_OBJECT') |