Add Image Operator: minor tweaks

- Use exception message on error.
- Use 3D view cursor location (for local view).
This commit is contained in:
2018-09-30 17:55:39 +10:00
parent f36efe0e2a
commit d9f6fdae4b

View File

@@ -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'}