get current image in uv editor ?

hello,

I tried bpy.data.screens[‘UV Editing’].areas[1].spaces[0].image

but it does not match the image currently visible in the uv editor

thanks

You can’t rely on screen names and area order, this is better:

for area in bpy.context.screen.areas:
    area.type == 'IMAGE_EDITOR':
        area.spaces.active.image

nice, but how do I show a popup if user did not open an uv editor or the image is not loaded ?

Does it make any sense to read the property if no uv editor is visible anyway?

Anyway, you could change the area.type temporarily…

If there’s no image, the property will be None

Maybe bpy.context.object.data.uv_textures.active.data[#].image is what you are looking for?

March 2015… Any ideas how to do this in 2021? :slight_smile:

import bpy

for a in bpy.context.screen.areas:
    if a.type == 'IMAGE_EDITOR':
        space = a.spaces[0]
        space.image = bpy.data.images[0] #change this to whatever image you want
2 Likes