0
$\begingroup$

I can’t find the answer to how to select an existing node through the script and apply the already added image without a GUI.

I have a ready-made script that opens a prepared blender file with saved materials, makes an import of the SVG curve and performs manipulations by adding these materials.

In one of the materials I need to change one picture. I found a code that can add a node with a new picture

import bpy
bpy.data.images.load("D:/temp/1.png", check_existing=True)
mat = bpy.context.view_layer.objects.active.active_material
tex = bpy.data.images.get('1.png')
image_node = mat.node_tree.nodes.new('ShaderNodeTexImage')
image_node.image = tex

This code created a new unconnected node and it needs to be connected to three other nodes. But I need only assign an already linked picture to the already connected node.

enter image description here

$\endgroup$
0
$\begingroup$

The solution was quite simple, though not found answer on the Internet.

import bpy
bpy.data.images.load("D:/badge/temp/1.png", check_existing=True)
mat = bpy.context.view_layer.objects.active.active_material
tex = bpy.data.images.get('1.png')
image_node = mat.node_tree.nodes["Image Texture"]
image_node.image = tex

At the same time, the desired node must be selected previously in the material so that everything works out.

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.