I am making a procedural material. I wanted to animate the scale
value. I wanted to animate in such a way that the scale value changes to the frame number
every time the frame number is a multiple of 10, so I scripted the following:
import bpy
frame_num = bpy.context.scene.frame_current
if frame_num % 10 == 0:
bpy.data.materials["noise"].node_tree.nodes["White Noise Texture"].inputs[1].default_value = frame_num
When I Run
the script it works as intended. But when I do not know how to link this script to the Animation. How do I run the script for each frame?
testure
February 12, 2020, 7:33pm
#2
yep, just use an app.handler for frame change. there’s one for before the frame changes and one for after it changes.
https://docs.blender.org/api/current/bpy.app.handlers.html#bpy.app.handlers.frame_change_post
It’s also possible to create custom python scripts for drivers:
I tried to call it with the prefix mathutils. in the driver expression but always ERROR: Invalid Python expression. In the Python Console, I call it as follows without importing the mathutils: mathutils.noise.noise(mathutils.Vector((10,20,30)),...
1 Like
I updated the script to the following:
import bpy
def trans_texture():
frame_num = bpy.context.scene.frame_current
if frame_num % 10 == 0:
bpy.data.materials["noise"].node_tree.nodes["White Noise Texture"].inputs[1].default_value = frame_num
bpy.app.handlers.frame_change_post.append(trans_texture)
But it does not read the script after every frame. What am I doing wrong here?
testure
February 13, 2020, 2:23am
#5
are you not getting an exception? app handlers require one positional argument (scene) and according to your code you haven’t supplied it.
take a look at the example on that same page I linked
1 Like