Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Odom <clockmender@icloud.com>2020-02-05 13:24:36 +0300
committerRune Morling <ermo.blender.org@spammesenseless.net>2020-02-05 14:28:12 +0300
commitb652724b15d99f91612ca2d55a1167a4b73ade12 (patch)
treee5317d625483b8cd6b3cc1453a65f9eecd493528 /precision_drawing_tools
parentf4f651c1e956776e4e37cb7b5245c3341d93660a (diff)
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.
Diffstat (limited to 'precision_drawing_tools')
-rw-r--r--precision_drawing_tools/pdt_library.py20
-rw-r--r--precision_drawing_tools/pdt_msg_strings.py1
2 files changed, 16 insertions, 5 deletions
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"