diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-09-30 10:55:39 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-09-30 10:55:39 +0300 |
commit | d9f6fdae4b5ae0475f0cbc8114a87b3be21739db (patch) | |
tree | 6185901801a247577097a55430b8aad60b812424 /release/scripts | |
parent | f36efe0e2ad5557fdd3f21ebc80e3e9e42533071 (diff) |
Add Image Operator: minor tweaks
- Use exception message on error.
- Use 3D view cursor location (for local view).
Diffstat (limited to 'release/scripts')
-rw-r--r-- | release/scripts/startup/bl_operators/object.py | 10 |
1 files 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'} |