pookie
pookie

Reputation: 4142

How to set a shader node property for Blender material via Python script?

enter image description here

Above is the material I've created. I exported my model to .obj from Blender. From a Python script (I have Blender compiled as a Python Module), I import my .obj file. I then attempt to set the Noise Texture 'W' property:

import bpy

bpy.ops.import_scene.obj( filepath = PATH_TO_MY_OBJ)
bpy.context.object.name = "obbb"
obj = bpy.data.objects["obbb"]

My material is called Material. How can I access the Noise Texture node and change the value of W?

I want to access the 'Noise Texture' node via python, so that I can randomize the 'W' property.

Upvotes: 2

Views: 2434

Answers (1)

DryFigs
DryFigs

Reputation: 19

    # accessing the materials
    material = bpy.data.materials.get("Material")
    
    # accessing all the nodes in that material
    nodes = material.node_tree.nodes
            
    # you can find the specific node by it's name
    noise_node = nodes.get("Noise Texture")

    # available inputs of that node
    # print([x.identifier for x in noise_node.inputs])
    # ['Vector', 'W', 'Scale', 'Detail', 'Distortion']

    # change value of "W"
    noise_node.inputs.get("W").default_value = 1

    

Upvotes: 1

Related Questions