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[0], height=size[1])
## For white image
# pixels = [1.0] * (4 * size[0] * size[1])
pixels = [None] * size[0] * size[1]
for x in range(size[0]):
for y in range(size[1]):
# assign RGBA to something useful
r = 0
g = 0
b = 0
a = 1.0
pixels[(y * size[0]) + 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'