0
$\begingroup$

I want to make an image display in UI panel so I find this how to display an image in blender UI with python? but when I run script of this which provided in how to display an image in blender UI with python?

import os
import bpy
import bpy.utils.previews

directory   = os.path.join(bpy.utils.user_resource('SCRIPTS'), "presets", "scatter_presets_custom\\")
list_raw = []

from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir(directory) if isfile(join(directory, f))]

for f in onlyfiles:
    if f[-4:] == ".jpg":
        list_raw.append(f)

class Panel(bpy.types.Panel):
    """Creates a Panel in the 3D view Tools panel"""
    bl_idname = "TEST_PT_Panel" 
    bl_label = "Scatter Icon test"
    bl_category = "Scatter BETA"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_context = "objectmode"

    def draw(self, context):
        global custom_icons

        for z in list_raw:
            self.layout.template_icon(icon_value=custom_icons[z[:-4]].icon_id,scale=10)

# global variable to store icons in
custom_icons = None

def register():
    global custom_icons
    custom_icons = bpy.utils.previews.new()

    for z in list_raw:
        custom_icons.load(z[:-4], os.path.join(directory, z), 'IMAGE')


    bpy.utils.register_class(Panel)

def unregister():
    global custom_icons
    bpy.utils.previews.remove(custom_icons)

    bpy.utils.unregister_class(Panel)

if __name__ == "__main__":
    register()

Blender showed this error Python script failed, check the message in the system console see the photo below enter image description here

enter image description here

So I go and check toggle system console and it showed this. I don't know what is the problem. enter image description here

I have a question on how to display an image in blender UI with python? Where can I paste the file location of my image? Can anyone tell me in where can I paste my file location of that photos or the script can find the path itself? 2nd question: Can I connect this script to the path which I searched in add-on preference enter image description here

$\endgroup$
7
  • $\begingroup$ @8NFILMS - Should we wait for your answer? $\endgroup$ Commented Apr 5, 2021 at 7:16
  • $\begingroup$ Who is @8NFILMS? $\endgroup$ Commented Apr 5, 2021 at 10:44
  • $\begingroup$ Do you know what can I do to fix this? If you know, please help me on the script. $\endgroup$ Commented Apr 5, 2021 at 10:45
  • $\begingroup$ To assist with debugging generic python errors. Recommend searching for "python FIleNotFoundError" $\endgroup$ Commented Apr 5, 2021 at 12:48
  • $\begingroup$ That's mean what code do I need to type? Where to search? $\endgroup$ Commented Apr 5, 2021 at 13:08

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.