I tried bpy.ops.texture.new() to create a new texture using python, however it does not work. I have seen another post here, but couldn't get this to work either. Ideally, I would like to give it a name as well:

bpy.data.textures["Texture"].type = 'VORONOI'
bpy.data.textures["Texture"].noise_intensity = 10
bpy.data.textures["Texture"].color_mode = 'POSITION_OUTLINE'
  • $\begingroup$ Does this help? Otherwise please add an example what kind of texture (node based, generic...). $\endgroup$ – brockmann Sep 17 '19 at 8:47
  • $\begingroup$ I've edited my post to clarify $\endgroup$ – Michael Teiniker Sep 17 '19 at 9:07

Name is no guaranty as another texture with the same name may exist. Use bpy.data.textures.new() and just pass a name as well as the modifier type:

import bpy

# Get the object and context
C = bpy.context
ob = C.object

# Generate the texture and set the attributes
voronoi_tex = bpy.data.textures.new("displace_voronoi", 'VORONOI')
voronoi_tex.noise_intensity = .5
voronoi_tex.noise_scale = .5
voronoi_tex.nabla = .05

# Displacement modifier
disp_mod = None
for modifier in ob.modifiers:
    if modifier.type == 'DISPLACE':
        disp_mod = modifier        

if not disp_mod:
    disp_mod = ob.modifiers.new(name='MyVoronoiDisplace', type='DISPLACE')

# Assign the texture
disp_mod.texture = voronoi_tex
disp_mod.strength = .5
disp_mod.vertex_group = "Group"
| improve this answer | |
  • $\begingroup$ It works perfectly in creating new textures, thank you. The only thing is that it doesn't link up to my displace modifier. In the modifier itself you can select the texture, the python code however does not select it yet..greatly appreciate this. $\endgroup$ – Michael Teiniker Sep 17 '19 at 10:08
  • $\begingroup$ @MichaelTeiniker, little bug. Corrected above and should work now $\endgroup$ – lemon Sep 17 '19 at 10:23
  • 1
    $\begingroup$ Should use disp_mod.vertex_group = "Group" as last line of the code above. Will edit it. In general, bpy.context needs a context in which you are sure that the good object is selected. That's why you should avoid it when possible. $\endgroup$ – lemon Sep 17 '19 at 10:44

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.