I’m trying to get this image I generate with my script to be assigned to an ‘Image or Movie’ type texture.
img = bpy.ops.image.new( name = obj.name + 'Color', width = 1024, height = 1024,
color = (0.0,0.0,0.0,0.0), alpha = True, generated_type ='BLANK')
But I keep getting the error:
Traceback (most recent call last):
File "\SFBetter_Paint.py", line 39, in execute
cTex.image = img
TypeError: bpy_struct: item.attr = val: ImageTexture.image expected a Image type, not set
location: <unknown location>:-1
Here’s a broader picture of the code:
#Create a new material and give it the name of the object
mat = bpy.data.materials.new(obj.name)
#Assign it some properties
mat.diffuse_shader = 'LAMBERT'
mat.darkness = 0.8
#Assign Material to the active object
obj.active_material = mat
#Create transparent image to be used as texture
img = bpy.ops.image.new( name = obj.name + 'Color', width = 1024, height = 1024,
color = (0.0,0.0,0.0,0.0), alpha = True, generated_type ='BLANK')
#Pack image into Blender File
bpy.ops.image.pack(as_png=True)
#Create A New texture
cTex = bpy.data.textures.new( name = obj.name + 'Color', type = 'IMAGE')
#Add a texture slot and assign it the texture we just created
mTex = mat.texture_slots.add()
mTex.texture = cTex
cTex.image = img