1

It seems to be easy but as a beginner, I can not configure it.

I have four blocks with different images. I add all four images using Images as Planes. Now I want to replace all four images with different images running script.

enter image description here

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51
SAHU
  • 73
  • 5
  • Do you want switch the image in the material node or change the material? – X Y May 01 '22 at 17:36
  • @XY Sir, I want to replace the image with a new one every time so I think changing the material will be a good option. Any other solution will be highly appreciated. – SAHU May 02 '22 at 02:55
  • here is the ans to change material of a object: https://blender.stackexchange.com/questions/53366/how-can-i-replace-a-material-from-python – X Y May 02 '22 at 03:08
  • @X Y Thanks, sir. I got the idea of how to change images with changing material. But it will be a huge help if you give some idea how to change images using material node. – SAHU May 02 '22 at 05:46

2 Answers2

2

Change Image Texture image

import bpy

mats = bpy.data.materials # all materials store in here

mat = mats["your Material"] # get a material

tree = mat.node_tree # get node tree of the material

nodes = tree.nodes # all nodes in node_tree

for node in nodes: if node.type == "TEX_IMAGE": print(node.name)

node = nodes["Image Texture"] # get node by name of node

imgs = bpy.data.images # all image in blend file

img = imgs["your img name"] # get a image

node.image = img # change image in node

node.image = None # change image to None

X Y
  • 5,234
  • 1
  • 6
  • 20
0

I suggest you try to use a video texture. if you encode with ffmpeg video and choose the webm encoder and setup trasnparency in the film render setting, the video can have transparency.

spiraloid
  • 369
  • 2
  • 5