I'm setting a Noise Texture node with W value to be linked to frame number (see picture). The idea is that generating noise as the result of the frame number * a coefficient (0.005).

I can make it via the Shaded Editor.

I need to replicate this in Python API

However, due to scalability I have to find a way to code it via the Python API. My script is the following

NoiseTextureStar = starMaterialNodeTree.nodes.new("ShaderNodeTexNoise")
NoiseTextureStar.noise_dimensions = '4D'
NoiseTextureStar.inputs[2].default_value = 102.800
NoiseTextureStar.inputs[3].default_value = 2.200
NoiseTextureStar.inputs[5].default_value = 0.261
NoiseTextureStar.inputs[5].default_value = 4

My first attempt was to include the following line:

NoiseTextureStar.inputs[1].default_value = #frame*0.0005


  1. "#" is escaped as a comment character in Python, and
  2. you can't multiply a string by a float.

Therefore, I'm looking for a way to read the current frame number while animating and use it a variable in Python.

My first attempt:

currentFrame = bpy.data.scenes['Scene'].frame_current

was unsuccessful because my Python script only read the first frame when executed.

Any suggestion is appreciated. Thanks in advance.


1 Answer 1

fcurve = NoiseTextureStar.inputs[1].driver_add('default_value')
fcurve.driver.expression = 'frame * 0.0005'

Search for "add driver python"


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .