1

I want to show an Image in my UI

enter image description here

I found the same question here but It didn't work for me

I haven't any error but It didn't show an Image in UI

import bpy

class ADDONNAME_PT_main_panel(bpy.types.Panel): bl_label = "Main Panel" bl_idname = "ADDONNAME_PT_main_panel" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = "New Tab"

def draw(self, context):
    layout = self.layout
    scene = context.scene

    obj = context.object


    row = layout.row()
    image = bpy.data.images.load("C:/Users/Kamali/Desktop/Test.png")

    row.template_ID_preview(image, "image", open="image.open")
    row.operator("addonname.myop_operator")
    row = layout.row()






class ADDONNAME_OT_my_op(bpy.types.Operator): bl_label = "Operator" bl_idname = "addonname.myop_operator"

def execute(self, context):
    scene = context.scene
    return {'FINISHED'}


classes = [ADDONNAME_PT_main_panel, ADDONNAME_OT_my_op]

def register(): for cls in classes: bpy.utils.register_class(cls)

def unregister(): for cls in classes: bpy.utils.unregister_class(cls) del bpy.types.Scene.my_tool

if name == "main": register()

but I can't see any texture in my panel?

enter image description here

I'm sure that my image loaded correctly

enter image description here

  • 1
    There are several ways of displaying an image, Another way: row.template_ID_preview(data, "image", open="image.open"). Please be more specific what exactly does not work. – brockmann Aug 30 '20 at 08:46
  • @brockmann your solution didn't work for me: row.template_ID_preview(bpy.data, "image", open = "C:/Users/Kamali/Desktop/Test.png") – Seyed Morteza Kamali Aug 30 '20 at 09:06
  • 1
    How to use it: https://docs.blender.org/api/current/bpy.types.UILayout.html?highlight=template_id_preview#bpy.types.UILayout.template_ID_preview – brockmann Aug 30 '20 at 09:10
  • 2
    Surely trying to load an image in a draw method is spitting errors constantly to console? Recommend double checking before chirping "it doesn't work" The open argument is an operator not a filepath. bpy.data has no property "image" – batFINGER Aug 30 '20 at 12:19
  • @batFINGER I tried to use @brockmann script but I had an error NameError: name 'data' is not defined so I changed it to bpy.data. I don't know what is data in his code.I tried pass an Image but didn't work! – Seyed Morteza Kamali Aug 30 '20 at 12:48
  • Just like any prop, foo.bar use row.template_ID_preview(foo, "bar") where the property "bar" of object foo is an image. – batFINGER Aug 30 '20 at 13:16
  • @batFINGER I updated my code and I used an Image it runs without any errors but there isn't any image in my panel – Seyed Morteza Kamali Aug 30 '20 at 14:09
  • For example an image texture node has an "image" property that is type bpy.types.Image. – batFINGER Aug 30 '20 at 15:15
  • 1
    There are errors. ui_template_id: pointer property not found: Image.image The object is an image which has no property "image" hence the error. Are you aware of how getattr(foo, "bar") works. Also See https://blender.stackexchange.com/questions/6173/where-does-console-output-go Finally loading an image in a draw method is not a good idea, this is why your "loaded image" image above is number 67... and counting. – batFINGER Aug 30 '20 at 17:38

0 Answers0