[Bf-extensions-cvs] [b652724b] blender-v2.82-release: PDT: Fix Library Error when not in Object Mode

Alan Odom noreply at git.blender.org
Wed Feb 5 12:28:52 CET 2020


Commit: b652724b15d99f91612ca2d55a1167a4b73ade12
Author: Alan Odom
Date:   Wed Feb 5 10:24:36 2020 +0000
Branches: blender-v2.82-release
https://developer.blender.org/rBAb652724b15d99f91612ca2d55a1167a4b73ade12

PDT: Fix Library Error when not in Object Mode

Attempts to Append, or Link Objects, Collections, or Materials when not in Object
mode resulted in a system error. This is now trapped as an Add-on error and
reported to the User.

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

M	precision_drawing_tools/pdt_library.py
M	precision_drawing_tools/pdt_msg_strings.py

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

diff --git a/precision_drawing_tools/pdt_library.py b/precision_drawing_tools/pdt_library.py
index c2565470..a0b1a6be 100644
--- a/precision_drawing_tools/pdt_library.py
+++ b/precision_drawing_tools/pdt_library.py
@@ -26,7 +26,7 @@ from bpy.types import Operator
 from mathutils import Vector
 from pathlib import Path
 from .pdt_functions import debug, oops
-from .pdt_msg_strings import PDT_ERR_NO_LIBRARY
+from .pdt_msg_strings import PDT_ERR_NO_LIBRARY, PDT_ERR_OBJECTMODE
 
 
 class PDT_OT_LibShow(Operator):
@@ -81,14 +81,19 @@ class PDT_OT_Append(Operator):
 
         scene = context.scene
         pg = scene.pdt_pg
+        obj = context.view_layer.objects.active
+        if obj is not None:
+            if obj.mode != "OBJECT":
+                error_message = PDT_ERR_OBJECTMODE
+                self.report({"ERROR"}, error_message)
+                return {"FINISHED"}
+
         obj_names = [o.name for o in context.view_layer.objects].copy()
         file_path = context.preferences.addons[__package__].preferences.pdt_library_path
         path = Path(file_path)
 
         if path.is_file() and ".blend" in str(path):
             if pg.lib_mode == "OBJECTS":
-                # Force object Mode
-                bpy.ops.object.mode_set(mode="OBJECT")
                 bpy.ops.wm.append(
                     filepath=str(path),
                     directory=str(path) + "/Object",
@@ -158,12 +163,17 @@ class PDT_OT_Link(Operator):
 
         scene = context.scene
         pg = scene.pdt_pg
+        obj = context.view_layer.objects.active
+        if obj is not None:
+            if obj.mode != "OBJECT":
+                error_message = PDT_ERR_OBJECTMODE
+                self.report({"ERROR"}, error_message)
+                return {"FINISHED"}
+
         file_path = context.preferences.addons[__package__].preferences.pdt_library_path
         path = Path(file_path)
         if path.is_file() and ".blend" in str(path):
             if pg.lib_mode == "OBJECTS":
-                # Force object Mode
-                bpy.ops.object.mode_set(mode="OBJECT")
                 bpy.ops.wm.link(
                     filepath=str(path),
                     directory=str(path) + "/Object",
diff --git a/precision_drawing_tools/pdt_msg_strings.py b/precision_drawing_tools/pdt_msg_strings.py
index 0c586200..8c7b9db2 100644
--- a/precision_drawing_tools/pdt_msg_strings.py
+++ b/precision_drawing_tools/pdt_msg_strings.py
@@ -84,6 +84,7 @@ PDT_LAB_PIVOTLOCH = "Location"
 # Error Message
 #
 PDT_ERR_NO_ACT_OBJ = "No Active Object - Please Select an Object"
+PDT_ERR_OBJECTMODE = "Library Append/Link Tools Work Only in Object Mode"
 PDT_OBJ_MODE_ERROR = "Only Mesh Object in Edit or Object Mode Supported"
 PDT_ERR_NO_ACT_VERT = "No Active Vertex - Select One Vertex Individually"
 PDT_ERR_NO_SEL_GEOM = "No Geometry/Objects Selected"



More information about the Bf-extensions-cvs mailing list