0
$\begingroup$

I have used a small script that Atom had published online, and it uses the index 0 for the image editor to then get the sizes of the image for setting render resolution. That art works great until you have more images loaded in blender, and then the index order may have changed. I want to get the index that matches the selected object's texture so that the operation doesn't mess up and use the wrong pixel resolution.

Any ideas here?

image_index = 0

    rnd = bpy.data.scenes[0].render  
    rnd.resolution_x, rnd.resolution_y = bpy.data.images[image_index].size[:]
$\endgroup$
2
$\begingroup$

Assuming the image of interest is on the first texture of the first material of the active object and you're using the Blender Internal (BI) render engine (not cycles):

import bpy

print( bpy.context.active_object.data.materials[0].texture_slots[0].texture.image.size[:] )
$\endgroup$
  • $\begingroup$ import bpy print(bpy.context.active_object.data.materials[0].texture_slots[0].texture.image.size[:]) I added the last parentheses and deleted the space behind the first, but thank you, that makes things much easier. $\endgroup$ – Craig D Jones Jan 30 '16 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.