From 69751991311a165e97a48ea67ed60e2c6022ee63 Mon Sep 17 00:00:00 2001
From: Robert Guetzkow <rjg>
Date: Fri, 6 Nov 2020 11:47:35 +0100
Subject: [PATCH] Fix T82405: Check if active object's data is None

Check if the active object's data is `None` before attempting
to call functions on it. It is `None` if the object is an
empty.

Reviewed By: campbellbarton

Differential Revision: https://developer.blender.org/D9456
---
 add_mesh_BoltFactory/Boltfactory.py               |  3 ++-
 add_mesh_extra_objects/Wallfactory.py             |  3 ++-
 add_mesh_extra_objects/add_mesh_beam_builder.py   |  3 ++-
 add_mesh_extra_objects/add_mesh_gears.py          |  6 ++++--
 add_mesh_extra_objects/add_mesh_gemstones.py      |  6 ++++--
 add_mesh_extra_objects/add_mesh_honeycomb.py      |  3 ++-
 add_mesh_extra_objects/add_mesh_pipe_joint.py     | 15 ++++++++++-----
 add_mesh_extra_objects/add_mesh_pyramid.py        |  3 ++-
 .../add_mesh_round_brilliant.py                   |  3 ++-
 add_mesh_extra_objects/add_mesh_round_cube.py     |  3 ++-
 add_mesh_extra_objects/add_mesh_star.py           |  3 ++-
 add_mesh_extra_objects/add_mesh_supertoroid.py    |  3 ++-
 add_mesh_extra_objects/add_mesh_torusknot.py      |  3 ++-
 add_mesh_extra_objects/add_mesh_twisted_torus.py  |  3 ++-
 add_mesh_geodesic_domes/third_domes_panel_271.py  |  3 ++-
 15 files changed, 42 insertions(+), 21 deletions(-)

diff --git a/add_mesh_BoltFactory/Boltfactory.py b/add_mesh_BoltFactory/Boltfactory.py
index 244d97203..330df8ae1 100644
--- a/add_mesh_BoltFactory/Boltfactory.py
+++ b/add_mesh_BoltFactory/Boltfactory.py
@@ -428,7 +428,8 @@ class add_mesh_bolt(Operator, AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if context.selected_objects != [] and context.active_object and \
-            ('Bolt' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('Bolt' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
diff --git a/add_mesh_extra_objects/Wallfactory.py b/add_mesh_extra_objects/Wallfactory.py
index 4b15b62ac..9ed8cb84d 100644
--- a/add_mesh_extra_objects/Wallfactory.py
+++ b/add_mesh_extra_objects/Wallfactory.py
@@ -885,7 +885,8 @@ class add_mesh_wallb(Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if context.selected_objects != [] and context.active_object and \
-            ('Wall' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('Wall' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
diff --git a/add_mesh_extra_objects/add_mesh_beam_builder.py b/add_mesh_extra_objects/add_mesh_beam_builder.py
index 5bb1bceb2..0cc43e0f8 100644
--- a/add_mesh_extra_objects/add_mesh_beam_builder.py
+++ b/add_mesh_extra_objects/add_mesh_beam_builder.py
@@ -761,7 +761,8 @@ class addBeam(Operator, object_utils.AddObjectHelper):
         if bpy.context.mode == "OBJECT":
 
             if context.selected_objects != [] and context.active_object and \
-            ('Beam' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('Beam' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
diff --git a/add_mesh_extra_objects/add_mesh_gears.py b/add_mesh_extra_objects/add_mesh_gears.py
index 9655dea9f..1d3bc70ec 100644
--- a/add_mesh_extra_objects/add_mesh_gears.py
+++ b/add_mesh_extra_objects/add_mesh_gears.py
@@ -689,7 +689,8 @@ class AddGear(Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if context.selected_objects != [] and context.active_object and \
-            ('Gear' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('Gear' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
@@ -910,7 +911,8 @@ class AddWormGear(Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if context.selected_objects != [] and context.active_object and \
-            ('WormGear' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('WormGear' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
diff --git a/add_mesh_extra_objects/add_mesh_gemstones.py b/add_mesh_extra_objects/add_mesh_gemstones.py
index fe31675df..dc505b0f9 100644
--- a/add_mesh_extra_objects/add_mesh_gemstones.py
+++ b/add_mesh_extra_objects/add_mesh_gemstones.py
@@ -284,7 +284,8 @@ class AddDiamond(Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if context.selected_objects != [] and context.active_object and \
-            ('Diamond' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('Diamond' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
@@ -433,7 +434,8 @@ class AddGem(Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if context.selected_objects != [] and context.active_object and \
-            ('Gem' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('Gem' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
diff --git a/add_mesh_extra_objects/add_mesh_honeycomb.py b/add_mesh_extra_objects/add_mesh_honeycomb.py
index 48a719401..bb6734a4c 100644
--- a/add_mesh_extra_objects/add_mesh_honeycomb.py
+++ b/add_mesh_extra_objects/add_mesh_honeycomb.py
@@ -278,7 +278,8 @@ class add_mesh_honeycomb(bpy.types.Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if context.selected_objects != [] and context.active_object and \
-            ('HoneyComb' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('HoneyComb' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
diff --git a/add_mesh_extra_objects/add_mesh_pipe_joint.py b/add_mesh_extra_objects/add_mesh_pipe_joint.py
index 984213315..91c64e2fc 100644
--- a/add_mesh_extra_objects/add_mesh_pipe_joint.py
+++ b/add_mesh_extra_objects/add_mesh_pipe_joint.py
@@ -230,7 +230,8 @@ class AddElbowJoint(Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if (context.selected_objects != []) and context.active_object and \
-            ('ElbowJoint' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('ElbowJoint' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
@@ -496,7 +497,8 @@ class AddTeeJoint(Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if (context.selected_objects != []) and context.active_object and \
-            ('TeeJoint' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('TeeJoint' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
@@ -779,7 +781,8 @@ class AddWyeJoint(Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if (context.selected_objects != []) and context.active_object and \
-            ('WyeJoint' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('WyeJoint' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
@@ -1126,7 +1129,8 @@ class AddCrossJoint(Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if (context.selected_objects != []) and context.active_object and \
-            ('CrossJoint' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('CrossJoint' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
@@ -1370,7 +1374,8 @@ class AddNJoint(Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if (context.selected_objects != []) and context.active_object and \
-            ('NJoint' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('NJoint' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
diff --git a/add_mesh_extra_objects/add_mesh_pyramid.py b/add_mesh_extra_objects/add_mesh_pyramid.py
index 405e6eaf1..58fafb047 100644
--- a/add_mesh_extra_objects/add_mesh_pyramid.py
+++ b/add_mesh_extra_objects/add_mesh_pyramid.py
@@ -168,7 +168,8 @@ class AddPyramid(bpy.types.Operator,  object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if context.selected_objects != [] and context.active_object and \
-            ('Pyramid' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('Pyramid' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
diff --git a/add_mesh_extra_objects/add_mesh_round_brilliant.py b/add_mesh_extra_objects/add_mesh_round_brilliant.py
index e50a1dbe5..874a26dba 100644
--- a/add_mesh_extra_objects/add_mesh_round_brilliant.py
+++ b/add_mesh_extra_objects/add_mesh_round_brilliant.py
@@ -428,7 +428,8 @@ class MESH_OT_primitive_brilliant_add(Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if context.selected_objects != [] and context.active_object and \
-            ('Brilliant' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('Brilliant' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
diff --git a/add_mesh_extra_objects/add_mesh_round_cube.py b/add_mesh_extra_objects/add_mesh_round_cube.py
index 1190be936..b48e9a691 100644
--- a/add_mesh_extra_objects/add_mesh_round_cube.py
+++ b/add_mesh_extra_objects/add_mesh_round_cube.py
@@ -405,7 +405,8 @@ class AddRoundCube(Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if context.selected_objects != [] and context.active_object and \
-            ('Roundcube' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('Roundcube' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
diff --git a/add_mesh_extra_objects/add_mesh_star.py b/add_mesh_extra_objects/add_mesh_star.py
index b5d515c6d..2bede0814 100644
--- a/add_mesh_extra_objects/add_mesh_star.py
+++ b/add_mesh_extra_objects/add_mesh_star.py
@@ -208,7 +208,8 @@ class AddStar(bpy.types.Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if context.selected_objects != [] and context.active_object and \
-            ('Star' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('Star' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
diff --git a/add_mesh_extra_objects/add_mesh_supertoroid.py b/add_mesh_extra_objects/add_mesh_supertoroid.py
index fabc8147d..8a87a289b 100644
--- a/add_mesh_extra_objects/add_mesh_supertoroid.py
+++ b/add_mesh_extra_objects/add_mesh_supertoroid.py
@@ -223,7 +223,8 @@ class add_supertoroid(bpy.types.Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if context.selected_objects != [] and context.active_object and \
-            ('SuperToroid' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('SuperToroid' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
diff --git a/add_mesh_extra_objects/add_mesh_torusknot.py b/add_mesh_extra_objects/add_mesh_torusknot.py
index 30957f7a6..39e985c30 100644
--- a/add_mesh_extra_objects/add_mesh_torusknot.py
+++ b/add_mesh_extra_objects/add_mesh_torusknot.py
@@ -144,7 +144,8 @@ class AddTorusKnot(bpy.types.Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if context.selected_objects != [] and context.active_object and \
-            ('TorusKnot' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('TorusKnot' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
diff --git a/add_mesh_extra_objects/add_mesh_twisted_torus.py b/add_mesh_extra_objects/add_mesh_twisted_torus.py
index 0502a1895..bb3bd4838 100644
--- a/add_mesh_extra_objects/add_mesh_twisted_torus.py
+++ b/add_mesh_extra_objects/add_mesh_twisted_torus.py
@@ -236,7 +236,8 @@ class AddTwistedTorus(bpy.types.Operator, object_utils.AddObjectHelper):
 
         if bpy.context.mode == "OBJECT":
             if context.selected_objects != [] and context.active_object and \
-            ('TwistedTorus' in context.active_object.data.keys()) and (self.change == True):
+                (context.active_object.data is not None) and ('TwistedTorus' in context.active_object.data.keys()) and \
+                (self.change == True):
                 obj = context.active_object
                 oldmesh = obj.data
                 oldmeshname = obj.data.name
diff --git a/add_mesh_geodesic_domes/third_domes_panel_271.py b/add_mesh_geodesic_domes/third_domes_panel_271.py
index 98add45f2..d95de4278 100644
--- a/add_mesh_geodesic_domes/third_domes_panel_271.py
+++ b/add_mesh_geodesic_domes/third_domes_panel_271.py
@@ -1293,7 +1293,8 @@ class GenerateGeodesicDome(Operator, object_utils.AddObjectHelper):
         if mesh != None:
             if bpy.context.mode == "OBJECT":
                 if context.selected_objects != [] and context.active_object and \
-                ('GeodesicDome' in context.active_object.data.keys()) and (self.change == True):
+                    (context.active_object.data is not None) and \
+                    ('GeodesicDome' in context.active_object.data.keys()) and (self.change == True):
                     obj = context.active_object
                     oldmesh = obj.data
                     oldmeshname = obj.data.name
-- 
GitLab