diff options
-rw-r--r-- | blenderkit/append_link.py | 39 | ||||
-rw-r--r-- | blenderkit/download.py | 32 | ||||
-rw-r--r-- | blenderkit/search.py | 13 | ||||
-rw-r--r-- | blenderkit/ui.py | 2 |
4 files changed, 57 insertions, 29 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') diff --git a/blenderkit/download.py b/blenderkit/download.py index c14fc84d..a93611c0 100644 --- a/blenderkit/download.py +++ b/blenderkit/download.py @@ -307,17 +307,15 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None, # copy for override al = sprops.append_link - import_as = sprops.import_as # set consistency for objects already in scene, otherwise this literally breaks blender :) ain = asset_in_scene(asset_data) + # override based on history if ain is not False: if ain == 'LINKED': al = 'LINK' - import_as = 'GROUP' else: al = 'APPEND' - import_as = 'INDIVIDUAL' # first get conditions for append link link = al == 'LINK' @@ -334,7 +332,7 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None, name=asset_data['name']) return - if sprops.import_as == 'GROUP': + if link: parent, newobs = append_link.link_collection(file_names[-1], location=downloader['location'], rotation=downloader['rotation'], @@ -343,12 +341,6 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None, parent=kwargs.get('parent')) else: - # parent, newobs = append_link.link_collection(file_names[-1], - # location=downloader['location'], - # rotation=downloader['rotation'], - # link=False, - # name=asset_data['name'], - # parent=kwargs.get('parent')) parent, newobs = append_link.append_objects(file_names[-1], location=downloader['location'], @@ -363,7 +355,7 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None, parent.empty_display_size = size_min elif kwargs.get('model_location') is not None: - if sprops.import_as == 'GROUP': + if link: parent, newobs = append_link.link_collection(file_names[-1], location=kwargs['model_location'], rotation=kwargs['model_rotation'], @@ -371,18 +363,14 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None, name=asset_data['name'], parent=kwargs.get('parent')) else: - # parent, newobs = append_link.link_collection(file_names[-1], - # location=kwargs['model_location'], - # rotation=kwargs['model_rotation'], - # link=False, - # name=asset_data['name'], - # parent=kwargs.get('parent')) parent, newobs = append_link.append_objects(file_names[-1], location=kwargs['model_location'], rotation=kwargs['model_rotation'], link=link, name=asset_data['name'], parent=kwargs.get('parent')) + + #scale Empty for assets, so they don't clutter the scene. if parent.type == 'EMPTY' and link: bmin = asset_data['bbox_min'] bmax = asset_data['bbox_max'] @@ -758,10 +746,12 @@ def asset_in_scene(asset_data): asset_data['file_name'] = ad['file_name'] asset_data['url'] = ad['url'] - c = bpy.data.collections.get(ad['name']) - if c is not None: - if c.users > 0: - return 'LINKED' + #browse all collections since linked collections can have same name. + for c in bpy.data.collections: + if c.name == ad['name']: + #there can also be more linked collections with same name, we need to check id. + if c.library and c.library.get('asset_data') and c.library['asset_data']['assetBaseId'] == id: + return 'LINKED' return 'APPENDED' return False diff --git a/blenderkit/search.py b/blenderkit/search.py index 82bb8f58..25d85d88 100644 --- a/blenderkit/search.py +++ b/blenderkit/search.py @@ -131,10 +131,15 @@ def update_assets_data(): # updates assets data on scene load. 'assets used', 'assets rated', ] - for d in dicts: - for k in d.keys(): - update_ad(d[k]) - # bpy.context.scene['assets used'][ad] = ad + for s in bpy.data.scenes: + for k in dicts: + d = s.get(k) + if not d: + continue; + + for k in d.keys(): + update_ad(d[k]) + # bpy.context.scene['assets used'][ad] = ad @persistent diff --git a/blenderkit/ui.py b/blenderkit/ui.py index 80b7ef2c..7ae6988a 100644 --- a/blenderkit/ui.py +++ b/blenderkit/ui.py @@ -738,7 +738,7 @@ def draw_callback_2d_search(self, context): highlight = (1, 1, 1, .2) # highlight = (1, 1, 1, 0.8) # background of asset bar - if not ui_props.dragging: + if not ui_props.dragging and ui_props.hcount>0: search_results = s.get('search results') search_results_orig = s.get('search results orig') if search_results == None: |