I'm writing an addon that bakes various passes to textures using cycles bake.
The script checks the geometry and works out which UDIM tiles the uvs on the mesh are occupying, creates a new image and then adds those tiles to the image. So far I've found two different ways to add tiles to the image:
Method 1:
image_name = obj.name + '_BakedTexture'
img = bpy.data.images.new(name=image_name, width=1024, height=1024, tiled=True,float_buffer=True, alpha=False)
new_tile = img.tiles.new(tile_number=1002)
This is my preferred method, since it avoids using bpy.ops, but I cant for the life of me figure out how to fill the UDIM tile.
Method 2:
image_name = obj.name + '_BakedTexture'
img = bpy.data.images.new(name=image_name, width=1024, height=1024, tiled=True,float_buffer=True, alpha=False)
bpy.context.area.ui_type = 'IMAGE_EDITOR'
bpy.context.space_data.image = img
bpy.ops.image.tile_add(number = 1002, generated_type = "UV_GRID", alpha=False, float=True)
Method 2 does everything I need it to do, since bpy.ops.image.tile_add has the added bonus of filling the tile, and this script works fine when run from the Text Editor in blender, but I get the following error when running it from a panel in the 3D View:
bpy.context.area.ui_type = 'IMAGE_EDITOR'
AttributeError: 'NoneType' object has no attribute 'ui_type'
I've looked at these two posts, which is how I got to this point:
UDIM tiles not importing properly image texture shader
Fill a UDIM tile with python API
But neither of them solves the above issue.
Thanks in advance!