I'm working on a part of an Addon that create a New Principled BSDF shader then a ShaderNodeTexImage (make it active), import an image with File brother and link it to the ShaderNodeTexImage.
Everything works except for the last step link it to the ShaderNodeTexImage
Texture_Node.image = ('img.name')
How can I tell blender get the name of the last image imported?
I've tried to create Lists before and after importing image and compare them to reach the new picture imported, but the command Texture_Node.image
expect a string not a list or a set.
and O'm sure there is a better way to reach the name of the last picture imported.
import bpy
material_bascic = bpy.data.materials.new(name= "New Mat")
material_bascic.use_nodes = True
bpy.context.object.active_material = material_bascic
principled_node = material_bascic.node_tree.nodes.get('Principled BSDF')
Texture_Node = material_bascic.node_tree.nodes.new('ShaderNodeTexImage')
Texture_Node.location = (-300,215)
material_bascic.node_tree.links.new(Texture_Node.outputs[0],principled_node.inputs[0])
nodes = material_bascic.node_tree.nodes
for node in nodes:
node.select = False
Texture_Node.select = True
nodes.active = Texture_Node
bpy.ops.image.open('INVOKE_DEFAULT')
#Texture_Node.image = img