From 9f59c24f1f3b75550a8189bf4080cc7e19838837 Mon Sep 17 00:00:00 2001
From: Alexander Gavrilov <angavrilov@gmail.com>
Date: Tue, 12 Jul 2022 18:04:32 +0300
Subject: [PATCH] Rigify: fix exceptions when generating from scratch.

---
 rigify/generate.py      | 2 +-
 rigify/utils/widgets.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/rigify/generate.py b/rigify/generate.py
index 53b47b006..d63399cc0 100644
--- a/rigify/generate.py
+++ b/rigify/generate.py
@@ -117,7 +117,7 @@ class Generator(base_generate.BaseGenerator):
         wgts_group_name = "WGTS_" + self.obj.name
         old_collection = bpy.data.collections.get(wgts_group_name)
 
-        if old_collection.library:
+        if old_collection and old_collection.library:
             old_collection = None
 
         if not old_collection:
diff --git a/rigify/utils/widgets.py b/rigify/utils/widgets.py
index ca207ddcc..5a16065b6 100644
--- a/rigify/utils/widgets.py
+++ b/rigify/utils/widgets.py
@@ -86,7 +86,7 @@ def create_widget(rig, bone_name, bone_transform_name=None, *, widget_name=None,
         if not obj:
             # Search the scene by name
             obj = scene.objects.get(obj_name)
-            if obj.library:
+            if obj and obj.library:
                 local_objs = [obj for obj in scene.objects if obj.name == obj_name and not obj.library]
                 obj = local_objs[0] if local_objs else None
 
-- 
GitLab