Skip to content
Snippets Groups Projects
Commit b652724b authored by Alan Odom's avatar Alan Odom Committed by Rune Morling
Browse files

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.
parent f4f651c1
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ from bpy.types import Operator ...@@ -26,7 +26,7 @@ from bpy.types import Operator
from mathutils import Vector from mathutils import Vector
from pathlib import Path from pathlib import Path
from .pdt_functions import debug, oops 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): class PDT_OT_LibShow(Operator):
...@@ -81,14 +81,19 @@ class PDT_OT_Append(Operator): ...@@ -81,14 +81,19 @@ class PDT_OT_Append(Operator):
scene = context.scene scene = context.scene
pg = scene.pdt_pg 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() obj_names = [o.name for o in context.view_layer.objects].copy()
file_path = context.preferences.addons[__package__].preferences.pdt_library_path file_path = context.preferences.addons[__package__].preferences.pdt_library_path
path = Path(file_path) path = Path(file_path)
if path.is_file() and ".blend" in str(path): if path.is_file() and ".blend" in str(path):
if pg.lib_mode == "OBJECTS": if pg.lib_mode == "OBJECTS":
# Force object Mode
bpy.ops.object.mode_set(mode="OBJECT")
bpy.ops.wm.append( bpy.ops.wm.append(
filepath=str(path), filepath=str(path),
directory=str(path) + "/Object", directory=str(path) + "/Object",
...@@ -158,12 +163,17 @@ class PDT_OT_Link(Operator): ...@@ -158,12 +163,17 @@ class PDT_OT_Link(Operator):
scene = context.scene scene = context.scene
pg = scene.pdt_pg 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 file_path = context.preferences.addons[__package__].preferences.pdt_library_path
path = Path(file_path) path = Path(file_path)
if path.is_file() and ".blend" in str(path): if path.is_file() and ".blend" in str(path):
if pg.lib_mode == "OBJECTS": if pg.lib_mode == "OBJECTS":
# Force object Mode
bpy.ops.object.mode_set(mode="OBJECT")
bpy.ops.wm.link( bpy.ops.wm.link(
filepath=str(path), filepath=str(path),
directory=str(path) + "/Object", directory=str(path) + "/Object",
......
...@@ -84,6 +84,7 @@ PDT_LAB_PIVOTLOCH = "Location" ...@@ -84,6 +84,7 @@ PDT_LAB_PIVOTLOCH = "Location"
# Error Message # Error Message
# #
PDT_ERR_NO_ACT_OBJ = "No Active Object - Please Select an Object" 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_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_ACT_VERT = "No Active Vertex - Select One Vertex Individually"
PDT_ERR_NO_SEL_GEOM = "No Geometry/Objects Selected" PDT_ERR_NO_SEL_GEOM = "No Geometry/Objects Selected"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment