How to add Image Browser to custom panel using Python or addon Serpens 3? Look like World Browser in this sample.
-
Should it be a panel/section in the World Properties tab or could it also be an area in the sidebar like this one here? – Blunder Dec 17 '22 at 20:30
-
@Blunder It doesn't really matter, but specifically I want to make a world textures switcher – M. Gordon Dec 18 '22 at 03:35
1 Answers
1) Property in the side panel
To create a property in the viewports side panel (N-panel)

use the script from this question (How to access pose bones via python in this condition?) and replace select_rig with select_image and these lines
# select_rig should point to an Object of type 'ARMATURE'
bpy.types.Scene.select_rig = bpy.props.PointerProperty(name='Select Rig',
type=bpy.types.Object, poll=scene_mychosenobject_poll)
with this line
bpy.types.Scene.select_image = bpy.props.PointerProperty(name='Image',type=bpy.types.Image)
2) Property in the World Properties window
import bpy
class SelectImagePanel(bpy.types.Panel):
"""Creates a Panel in the World properties window"""
bl_label = "World Image Panel"
bl_idname = "OBJECT_PT_select_image"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "world"
def draw(self, context):
layout = self.layout
obj = context.active_object
row = layout.row()
row.label(text="Select an image", icon='WORLD_DATA')
row = layout.row()
row.prop(context.scene, 'select_image')
def register():
bpy.utils.register_class(SelectImagePanel)
bpy.types.Scene.select_image = bpy.props.PointerProperty(name='Image',type=bpy.types.Image)
def unregister():
bpy.utils.unregister_class(HelloWorldPanel)
if name == "main":
register()
Related questions:
- 13,925
- 4
- 13
- 36
-
Thank you very much for your answer! I meant a specific image how to change? For example "Sky Image" from World Shader. Sorry, my python skill is very beginning – M. Gordon Dec 20 '22 at 16:25

