I'm working on an addon that requires me to generate and fill UDIM tiles in a texture with the python API, however I am stuck at the point of filling the tile.

The following code creates a new tiled texture and adds a new tile, storing the new tile as a variable:

udim_tex = bpy.data.images.new(name="UDIM Texture", width=1024, height=1024, tiled=True)          
new_tile = udim_tex.tiles.new(tile_number=1002)

At this point, I am looking for a method to fill the new_tile, but this doesn't seem to be possible in the same way that it is possible to fill a normal image texture using the generated_color method.

An alternative seems to be to use the operator:

bpy.ops.image.tile_fill(color=(0, 0, 0, 0), width=new_width, height=new_height)

But in this case I can't figure out the correct context to use (I have tried, unsuccessfully, using overrides etc.). I always see the following error message from the operator's poll:

enter image description here

My ultimate goal is basically to be able to create a new UDIM tile that is filled with alpha=0 everywhere, so if there is a better approach to this that would also work!

Thanks in advance.


1 Answer 1

udim_tex = bpy.data.images.new(name="UDIM Texture", width=1024, height=1024, tiled=True)          
new_tile = udim_tex.tiles.new(tile_number=1002)`

#You have to be in the proper context:
bpy.context.area.ui_type = 'IMAGE_EDITOR'

#select the image you have created:
bpy.context.space_data.image = udim_tex

bpy.ops.image.tile_fill(color=(0, 0, 0, 0), width=500, height=500, float=False, 
#However, you can return to the initial context area:
#bpy.context.area.ui_type = 'ShaderNodeTree

I know is not the best solution but it seems to work.


You must log in to answer this question.

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