From d9f6fdae4b5ae0475f0cbc8114a87b3be21739db Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 30 Sep 2018 17:55:39 +1000 Subject: Add Image Operator: minor tweaks - Use exception message on error. - Use 3D view cursor location (for local view). --- release/scripts/startup/bl_operators/object.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/release/scripts/startup/bl_operators/object.py b/release/scripts/startup/bl_operators/object.py index 98d3d0c8c6d..f68ebfc4b94 100644 --- a/release/scripts/startup/bl_operators/object.py +++ b/release/scripts/startup/bl_operators/object.py @@ -869,6 +869,7 @@ class DupliOffsetFromCursor(Operator): return {'FINISHED'} + class LoadImageAsEmpty(Operator): """Select an image file and create a new image empty with it""" bl_idname = "object.load_image_as_empty" @@ -887,13 +888,16 @@ class LoadImageAsEmpty(Operator): return {'RUNNING_MODAL'} def execute(self, context): + scene = context.scene + space = context.space_data + cursor = (space if space and space.type == 'VIEW_3D' else scene).cursor_location try: image = bpy.data.images.load(self.filepath, check_existing=True) - except RuntimeError: - self.report({"ERROR"}, "cannot load image") + except RuntimeError as ex: + self.report({"ERROR"}, str(ex)) return {"CANCELLED"} - bpy.ops.object.empty_add(type='IMAGE', location=context.scene.cursor_location) + bpy.ops.object.empty_add(type='IMAGE', location=cursor) context.active_object.data = image return {'FINISHED'} -- cgit v1.2.3