Image select/load controls for custom panel?

Hi.

Does anyone know if there’s a built-in/predefined way for a custom panel to have its own image loading/selection controls, like the ones that we see in the Materials > Surface panel?

This is what we see for the Image Texture input of a simple material before a choice has been made:
Load Image 1

And these are shown afterwards so the user can change it:
image

If this has to be done manually, I’m thinking the image button is an EnumProperty which uses the images data block. The buttons may just be operators. I’d be happy for my own implementation to be quite simple (e.g. assume the image is already loaded and just have the drop-down and text field)

Background info:
I’ve written an addon which, among other things, gets the diffuse textures assigned to an object’s materials (part of an export process which copies all relevant files to some other directory). In most cases the materials will be simple enough to analyze (get the Output node, look at input 0 to get the Shader node, look at its input 0 to get the Texture node).

There will be very rare cases in which the user has a more involved node setup, e.g. to show texture alpha or apply brightness to a dark texture to make editing easier. I think it would be impossible to anticipate what someone else will do, so the above idea seems like a better way of managing these rare scenarios.

Hello, you can get this interface if you use https://docs.blender.org/api/current/bpy.types.UILayout.html#bpy.types.UILayout.template_ID

An example of how it’s used in the image editor :

layout.template_ID(sima, "image", new="image.new", open="image.open")

1 Like