Skip to content
Snippets Groups Projects
download.py 40.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • Vilem Duha's avatar
    Vilem Duha committed
            au = s.get('assets used')
            if au == None:
                s['assets used'] = {}
    
            if asset_base_id in s.get('assets used'):
                # already used assets have already download link and especially file link.
                asset_data = s['assets used'][asset_base_id].to_dict()
    
    Vilem Duha's avatar
    Vilem Duha committed
            if bpy.context.mode != 'OBJECT' and (
    
                    atype == 'model' or atype == 'material') and bpy.context.view_layer.objects.active is not None:
    
    Vilem Duha's avatar
    Vilem Duha committed
                bpy.ops.object.mode_set(mode='OBJECT')
    
    
            if self.replace:  # cleanup first, assign later.
    
                obs = utils.get_selected_replace_adepts()
    
    Vilém Duha's avatar
    Vilém Duha committed
                # print(obs)
    
                    print('replace attempt ', ob.name)
                    if self.asset_base_id != '':
                        # this is for a case when replace is called from a panel, this makes the first of the objects not replacable.
                        if ob.get('asset_data') is not None and ob['asset_data']['assetBaseId'] == self.asset_base_id:
                            print('skipping this oneli')
                            continue;
    
    
                    kwargs = {
                        'cast_parent': self.cast_parent,
                        'target_object': ob.name,
                        'material_target_slot': ob.active_material_index,
                        'model_location': tuple(ob.matrix_world.translation),
                        'model_rotation': tuple(ob.matrix_world.to_euler()),
                        'replace': False,
                        'parent': ob.parent
                    }
                    utils.delete_hierarchy(ob)
                    start_download(asset_data, **kwargs)
            else:
                kwargs = {
                    'cast_parent': self.cast_parent,
                    'target_object': self.target_object,
                    'material_target_slot': self.material_target_slot,
                    'model_location': tuple(self.model_location),
                    'model_rotation': tuple(self.model_rotation),
                    'replace': False
                }
    
                start_download(asset_data, **kwargs)
    
    Vilem Duha's avatar
    Vilem Duha committed
            return {'FINISHED'}
    
    
    def register_download():
        bpy.utils.register_class(BlenderkitDownloadOperator)
    
        bpy.utils.register_class(BlenderkitKillDownloadOperator)
    
    Vilem Duha's avatar
    Vilem Duha committed
        bpy.app.handlers.load_post.append(scene_load)
        bpy.app.handlers.save_pre.append(scene_save)
    
        user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
        if user_preferences.use_timers:
            bpy.app.timers.register(timer_update)
    
    Vilem Duha's avatar
    Vilem Duha committed
    
    
    def unregister_download():
        bpy.utils.unregister_class(BlenderkitDownloadOperator)
    
        bpy.utils.unregister_class(BlenderkitKillDownloadOperator)
    
    Vilem Duha's avatar
    Vilem Duha committed
        bpy.app.handlers.load_post.remove(scene_load)
        bpy.app.handlers.save_pre.remove(scene_save)
    
        if bpy.app.timers.is_registered(timer_update):
            bpy.app.timers.unregister(timer_update)