Image.New weirdness

I’m writing an import script. The data I’m importing gives me UVs and texture names, but not the location of the texture. So I need to assign faces to a texture without loading it into Blender.

imageHandle = Blender.Image.New(texName,128,128,32)

# later on...

self.mesh.faces[-1].image = imageHandle

This code creates a new image and assigns the face to it as I expected. But there are two problems:

  • The generated texture is pure black. How can I get the UV test grid?
  • I expected the user to be able to replace the generated image with an actual file. But UV Editor > Image > Replace… has no effect whatsoever; the image chosen isn’t even loaded into a different datablock, let alone active one. I’m stuck with the black texture that I can’t even delete from the scene! Replacing an image does work if the user has opened it through the UI.

Am I missing some vital stage here? Why can’t the user replace the stand-in image?

Okay, solved the problem. I didn’t understand how the skinning system works (had no reason to before now, since I export to this format as well).

I should have been creating a Material for each texture listed in the file, then assign its index to self.mesh.faces[-1].mat. This leaves the Image undefined, sidestepping the whole issue with the black images, and makes it far easier to handle having multiple textures on one mesh.

Still would like to know how to generate the UV test grid though!