[Bf-blender-cvs] [6791d95b1db] blender2.8: Empty Object: new "Load Image as Empty" operator

Jacques Lucke noreply at git.blender.org
Thu Sep 27 16:23:18 CEST 2018


Commit: 6791d95b1db8a2419b9534e95ea7c73c1cb4ff62
Author: Jacques Lucke
Date:   Thu Sep 27 16:21:51 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB6791d95b1db8a2419b9534e95ea7c73c1cb4ff62

Empty Object: new "Load Image as Empty" operator

New entry in the Add Object menu.
Opens a file selector and creates a new empty object from the selected image.
Previously more steps were needed to archieve the same.

Differential: https://developer.blender.org/D3708

Reviewer: brecht

===================================================================

M	release/scripts/startup/bl_operators/object.py
M	release/scripts/startup/bl_ui/space_view3d.py

===================================================================

diff --git a/release/scripts/startup/bl_operators/object.py b/release/scripts/startup/bl_operators/object.py
index 30a9943df71..98d3d0c8c6d 100644
--- a/release/scripts/startup/bl_operators/object.py
+++ b/release/scripts/startup/bl_operators/object.py
@@ -869,12 +869,41 @@ 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"
+    bl_label = "Load Image as Empty"
+    bl_options = {'REGISTER'}
+
+    filepath: StringProperty(
+        subtype='FILE_PATH'
+    )
+
+    filter_image: BoolProperty(default=True, options={'HIDDEN', 'SKIP_SAVE'})
+    filter_folder: BoolProperty(default=True, options={'HIDDEN', 'SKIP_SAVE'})
+
+    def invoke(self, context, event):
+        context.window_manager.fileselect_add(self)
+        return {'RUNNING_MODAL'}
+
+    def execute(self, context):
+        try:
+            image = bpy.data.images.load(self.filepath, check_existing=True)
+        except RuntimeError:
+            self.report({"ERROR"}, "cannot load image")
+            return {"CANCELLED"}
+
+        bpy.ops.object.empty_add(type='IMAGE', location=context.scene.cursor_location)
+        context.active_object.data = image
+        return {'FINISHED'}
+
 
 classes = (
     ClearAllRestrictRender,
     DupliOffsetFromCursor,
     IsolateTypeRender,
     JoinUVs,
+    LoadImageAsEmpty,
     MakeDupliFace,
     SelectCamera,
     SelectHierarchy,
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 328ed854044..898f22a8ca9 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -1518,6 +1518,10 @@ class VIEW3D_MT_add(Menu):
         layout.menu("VIEW3D_MT_armature_add", icon='OUTLINER_OB_ARMATURE')
         layout.operator("object.add", text="Lattice", icon='OUTLINER_OB_LATTICE').type = 'LATTICE'
         layout.operator_menu_enum("object.empty_add", "type", text="Empty", icon='OUTLINER_OB_EMPTY')
+
+        sublayout = layout.column()
+        sublayout.operator_context = 'INVOKE_DEFAULT'
+        sublayout.operator("object.load_image_as_empty", text="Image", icon="IMAGE_DATA")
         layout.separator()
 
         layout.operator("object.speaker_add", text="Speaker", icon='OUTLINER_OB_SPEAKER')



More information about the Bf-blender-cvs mailing list