I want to create a texture of type 'noise' and modify its influence rgb value. Doing this in Blender, I see the following in the info window:

bpy.data.textures["Texture"].type = 'NOISE'
bpy.context.object.active_material.texture_slots[0].color =
    (0.676377, 1, 0.268503)

Trying to translate this to a python script:

myTexture = bpy.data.textures.new("myTexture", type="NOISE");

myMaterial = bpy.data.materials.new(name="myMaterial");
myMaterial.diffuse_color = (1, 1, 1);
myMaterial.texture_slots[0].color = (0.45778, 1, 0.223341);

the last line fails:

AttributeError: 'NoneType' object has no attribute 'color'

What's the right way to do this? Here's a screenshot of the blender UI, I have a new texture selected, and I'm modifying the rgb box at the bottom:

enter image description here



Here's some sample code for creating a new material, texture slot, texture and setting it all up together as specified in your question:

m                   = bpy.data.materials.new( "MyMat" )
m.diffuse_color     = (1, 1, 1);
obj.active_material = m

ts                      = m.texture_slots.create(0)
ts.texture_coords       = 'UV' # Assuming this is what you want, could be any of the following: ('GLOBAL', 'OBJECT', 'ORCO', 'UV', 'STRAND', 'WINDOW', 'NORMAL', 'REFLECTION', 'STRESS', 'TANGENT')
ts.color                = (0.45778, 1, 0.223341)
ts.texture              = bpy.data.textures.new( "TEXTURE", "NOISE" )

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.