I made a plugin to use on blender, installing the plugin will display a panel, and I wanted to display an image on that panel, so I create a texture in the script file with type 'IMAGE':
ui_tex = bpy.data.textures.new('MP', 'IMAGE')
and then when I assign it an image it doesn't seem to load the image:
ui_tex.image = bpy.data.images.load("D:/pic.png")
So how can I load an image from the script file to a newly created texture. Note: the previous two python statements are written in a draw function of the panel
Edit: Here is the class for the panel with the draw function:
class UIPanel(bpy.types.Panel):
bl_label = "Label"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
br_name = "Printing"
def draw(self, context):
layout = self.layout
scn = context.scene
ui_tex = bpy.data.textures.new("MP", "IMAGE")
ui_tex.image = bpy.data.images.load("D:/pic.png")
row = layout.row(align=True)
row.alignment = 'EXPAND'
row.template_preview(bpy.data.textures["MP"])
Might I add that I get this error in the blender system console:
line 39, in draw
ui_tex.image = bpy.data.images.load(filepath = filepath)
AttributeError: Writing to ID classes in this context is not allowed: MP, Texture datablock, error setting ImageTexture.image