i have trouble to get a script working within Blender 2.8. The following function work perfectly for me in Blender 2.79, but not in 2.8.
def CreateMaterialFromImage(matName, imgPath):
'''Creates and returns a material from an Image'''
realpath = os.path.expanduser(imgPath)
try:
img = bpy.data.images.load(realpath)
except:
raise NameError("Cannot load image %s" % realpath)
# Create image texture from image
cTex = bpy.data.textures.new(matName, type='IMAGE')
cTex.image = img
# Create material
mat = bpy.data.materials.new(matName)
# Add texture slot for color texture
mtex = mat.texture_slots.add()
mtex.texture = cTex
mtex.texture_coords = 'UV'
mtex.use_map_color_diffuse = True
mtex.use_map_color_emission = True
mtex.emission_color_factor = 0.5
mtex.use_map_density = True
mtex.mapping = 'FLAT'
return mat
It seems to be that the material.texture_slots were removed.
Under following Link https://lists.blender.org/pipermail/bf-blender-cvs/2018-April/106620.html i found the note:
- Texture slots for materials, lamps and world were removed. They remain for brushes, particles and freestyle linestyles.
So my question is where do i find this property now or how could i change my code to get things done?
Thanks for your help!
EDIT: https://en.blender.org/index.php/Dev:2.8/Source/Python/UpdatingScripts This seems to be an interesting link for people run in to issues by updating their scripts to 2.8. Unfortunately there is no solution for my problem listed, yet.
ValueError
instead ofNameError
, name error is for variable not found by name. eg. didn't assign it before access the variable. $\endgroup$