[Bf-extensions-cvs] [d7e9c0f2] master: BlenderKit: Don't run blenderkit checks when running in background

Vilem Duha noreply at git.blender.org
Sun Apr 21 21:21:51 CEST 2019


Commit: d7e9c0f2047e139c7e2e19b5c95f5e59f92caada
Author: Vilem Duha
Date:   Sat Apr 20 12:45:38 2019 +0200
Branches: master
https://developer.blender.org/rBAd7e9c0f2047e139c7e2e19b5c95f5e59f92caada

BlenderKit: Don't run blenderkit checks when running in background

===================================================================

M	blenderkit/download.py
M	blenderkit/utils.py

===================================================================

diff --git a/blenderkit/download.py b/blenderkit/download.py
index 65dc631b..c1db12ea 100644
--- a/blenderkit/download.py
+++ b/blenderkit/download.py
@@ -106,8 +106,9 @@ def check_unused():
 def scene_save(context):
     ''' does cleanup of blenderkit props and sends a message to the server about assets used.'''
     # TODO this can be optimized by merging these 2 functions, since both iterate over all objects.
-    check_unused()
-    report_usages()
+    if not bpy.app.background:
+        check_unused()
+        report_usages()
 
 
 @persistent
diff --git a/blenderkit/utils.py b/blenderkit/utils.py
index 336b4ab1..2c12f0e7 100644
--- a/blenderkit/utils.py
+++ b/blenderkit/utils.py
@@ -175,26 +175,27 @@ def load_prefs():
             user_preferences.global_dir = prefs['global_dir']
 
 def save_prefs(self, context):
-    user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
-    if user_preferences.api_key != '':
-        print(len(user_preferences.api_key))
-        print('length')
-        if len(user_preferences.api_key)>35:
-            prefs = {
-                'API_key': user_preferences.api_key,
-                'global_dir': user_preferences.global_dir,
-            }
-            # user_preferences.api_key = user_preferences.api_key.strip()
-            fpath = paths.BLENDERKIT_SETTINGS_FILENAME
-            f = open(fpath, 'w')
-            with open(fpath, 'w') as s:
-                json.dump(prefs, s)
-            bpy.ops.wm.save_userpref()
-        else:
-            # reset the api key in case the user writes some nonsense, e.g. a search string instead of the Key
-            user_preferences.api_key = ''
-            props = get_search_props()
-            props.report = 'Please paste a correct API Key.'
+    if not bpy.app.background:
+        user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
+        if user_preferences.api_key != '':
+            print(len(user_preferences.api_key))
+            print('length')
+            if len(user_preferences.api_key)>35:
+                prefs = {
+                    'API_key': user_preferences.api_key,
+                    'global_dir': user_preferences.global_dir,
+                }
+                # user_preferences.api_key = user_preferences.api_key.strip()
+                fpath = paths.BLENDERKIT_SETTINGS_FILENAME
+                f = open(fpath, 'w')
+                with open(fpath, 'w') as s:
+                    json.dump(prefs, s)
+                bpy.ops.wm.save_userpref()
+            else:
+                # reset the api key in case the user writes some nonsense, e.g. a search string instead of the Key
+                user_preferences.api_key = ''
+                props = get_search_props()
+                props.report = 'Please paste a correct API Key.'
 
 def load_categories():
     categories.copy_categories()



More information about the Bf-extensions-cvs mailing list