get current image in uv editor ?


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

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


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

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

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[#].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 =[0] #change this to whatever image you want
1 Like