So I've been making a system that needs a lot of masks, and I need a script/addon to automatically make blank mask images at a set resolution, named appropriately, and put into the proper Image Node.
This is Blender 2.93 BTW if that makes any different to syntax.
I found some blocks of code to do different bits of this, and I have it mostly working, but for some reason it doesn't put it in the Image Node.
size = 1024, 1024 import bpy # blank image image = bpy.data.images.new("NipRough", width=size, height=size) ## For white image # pixels = [1.0] * (4 * size * size) pixels = [None] * size * size for x in range(size): for y in range(size): # assign RGBA to something useful r = 0 g = 0 b = 0 a = 1.0 pixels[(y * size) + x] = [r, g, b, a] # flatten list pixels = [chan for px in pixels for chan in px] # assign pixels image.pixels = pixels # write image image.filepath_raw = "//NipRough.png" image.file_format = 'PNG' image.save() # **works fine up to here** # find node and assign the texture to it bpy.data.images.load("//NipRough.png", check_existing=True) mat = bpy.data.materials["Skin"] node = bpy.data.materials["Skin"].node_tree.nodes["NipRough"].name tex = ('//NipRough.png') node.image = tex
It keeps telling me:
line 39, in "< module >" AttributeError: 'str' object has no attribute 'image'