import bpy
from bpy.props import *

class primitive_object_add(bpy.types.Operator):
    '''Add a minecraft item'''
    bl_idname = "mesh.primitive_object_add"
    bl_label = "Add a Minecraft item"
    bl_options = {'REGISTER', 'UNDO'}
    img_str = StringProperty(name="Path:", default="", subtype='FILE_PATH')
    opt = IntProperty(name="Option 2:")

    def execute(self, context):
        if self.img_str != "":
            path = r"" + bpy.path.abspath(self.img_str)
            image = bpy.data.images.load(path)
        return {'FINISHED'}

def menu_func(self, context):
    self.layout.operator("mesh.primitive_object_add", text="Object", icon='OBJECT_DATA')
def register():
def unregister():
if __name__ == "__main__":

So if running this code, following happens:

You get up the menu and everything just fine enter image description here

Then clicking the file browser icon, which will bring up the file browser, so far everything is working. enter image description here

However, now when selecting an image and pressing accept, will load the image into blender properly, but it locks/freezes the toolbar, so now I cannot change Option 2 if I would like to. enter image description here

I've spent pretty much the entire day yesterday trying to fix this, but without any luck. I discovered that for some reason if you where to press "Object" in the add menu 2 times and then using the file browser to load in an image it works, and it will work until you close and open blender again.

Does anyone have any idea on why this might be happening, and a way to fix it or go around the problem?

  • 1
    $\begingroup$ see this alternative blender.stackexchange.com/a/17829/5113 $\endgroup$
    – Chebhou
    May 26, 2015 at 16:09
  • $\begingroup$ @Chebhou The problem using 'bpy.ops.image.open("INVOKE_DEFAULT")' is that for the add-on I'm working on I need a reference to the image, and the action needs to happen when pressing a button, and if I'm not mistaken it's not possible to add buttons in the current panel I'm using. $\endgroup$ May 26, 2015 at 16:37
  • $\begingroup$ you can add buttons, and if you need a ref to the image store a list of the images before calling the Op then compare it with the new list the new entry is yours $\endgroup$
    – Chebhou
    May 26, 2015 at 16:39
  • $\begingroup$ @Chebho Sounds like that could work, however with my limited knowledge of Python I have no idea on how I would do this. Any chance you could help me out? (It would of course be paid). If you're interested, hit me up at [email protected] $\endgroup$ May 26, 2015 at 17:48
  • $\begingroup$ there's a problem that the image is not pushed into the bpy.data until the operator is finished which make it impossible to find a reference for so you may have to create a panel for your addon to avoid all this hustle if you can add more details I may be able to help $\endgroup$
    – Chebhou
    May 27, 2015 at 2:36


You must log in to answer this question.

Browse other questions tagged .