0
$\begingroup$

How to create a new image texture using python scripting ?

I tried this :

texture = bpy.data.textures.new('image.png', type='IMAGE')
texture.image = bpy.data.images['image.png'] 

or

bpy.ops.texture.new()
texture = bpy.data.textures['Texture']
texture.image = bpy.data.images['image.png'] 

the texture is not created in the interface :

enter image description here

enter image description here

thank you

$\endgroup$
2
  • $\begingroup$ The first method (first two lines of code) should work. The second method (last four lines of code) has a bug. You shouldn't assume that the new texture is the last one in the list, since the list is alphabetically sorted. Anyway, I suspect the issue is with the texture picker in the UI. $\endgroup$ Commented Oct 11 at 9:44
  • 1
    $\begingroup$ Please use tags like python and/or scripting when you're asking about python scripting. Some people here actually use these tags for filtering. $\endgroup$ Commented Oct 11 at 15:10

1 Answer 1

1
$\begingroup$

Textures created in the current blend file cannot be used on the linked, Essential brushes. The textures need to be created in the blend file {Blender Folder}/{Blender Version}/datafiles/assets/brushes/essentials_brushes-mesh_texture.blend. An alternative option is to create a local brush which should be able to use local textures. The following script does the latter. There are many settings that you may want to set on the new brush and/or on the new texture. The script doesn't include any of that.

import bpy

# Create a new brush
new_brush = bpy.data.brushes.new("New Brush", mode='TEXTURE_PAINT')
# Mark the new brush as an asset to be able to select it in the Asset Shelf
new_brush.asset_mark()
# Create a new texture
new_texture = bpy.data.textures.new("New Texture", 'IMAGE')
# Assign the new texture to the new brush
new_brush.texture_slot.texture = new_texture
$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.