4
$\begingroup$

After creating an image using:

bpy.data.images.new(name="NewImage2", width=512, height=512)

How would I set that image to the active image within the UV/Image Editor in Python?

Set Image in UV Editor Active?

$\endgroup$

2 Answers 2

9
$\begingroup$

You loop through area till you find the UV/Image editor and set the active image to you image

for area in bpy.context.screen.areas :
    if area.type == 'IMAGE_EDITOR' :
            area.spaces.active.image = my_img
$\endgroup$
2
  • $\begingroup$ Is there a way to do this if that space isn't open? $\endgroup$
    – Andy Ray
    Jul 6, 2016 at 7:10
  • $\begingroup$ @user53145 try changing spaces.active to something like spaces["myspace"] $\endgroup$
    – Chebhou
    Jul 6, 2016 at 18:08
1
$\begingroup$

Here's the correct way to do it. This will work even if the UV Editor pane isn't open:

bpy.ops.image.new(name='Some Name')
image = bpy.data.images['Some Name']

bpy.data.screens['UV Editing'].areas[1].spaces[0].image = image
$\endgroup$
1
  • 4
    $\begingroup$ This would only work if you don't change your Blender screen layout at all. @Chebhou's answer is more robust. $\endgroup$
    – dr. Sybren
    Jul 22, 2016 at 13:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .