I would like to create a mix and texture node in the compositor with python.
Here is my code:
import bpy
import os
from bpy import context, data, ops
#*******************Texture*********************************
#Creation of a new texture
bpy.ops.texture.new()
#Give a name to the texture
bpy.data.textures["Noise"].name = "Noise"
#Define the type of texture, here noise
bpy.data.textures["Noise"].type = 'NOISE'
#*****************Compositing ******************************
#To have more light on the picture and something more realistic
bpy.context.scene.view_settings.view_transform = 'Standard'
#Switch on nodes and get reference
bpy.context.scene.use_nodes = True
tree = bpy.context.scene.node_tree
#Clear default node
for node in tree.nodes:
tree.nodes.remove(node)
#Creation of the input, where the image is loading
image_node = tree.nodes.new(type='CompositorNodeImage') # Create a new image node
image_node.location = 0,0
#Create mix node
mix_node = tree.nodes.new(type='ShaderNodeGroup')
mix_node.location = 0,0
#Create texture node
texture_node = tree.nodes.new('ShaderNodeTexImage')
texture_node.location = 0,100
texture_node.texture = bpy.data.textures["Noise"]
#Creation of the final node (Compose = storage of the final result)
comp_node = tree.nodes.new('CompositorNodeComposite')
comp_node.location = 400,0
path = 'D:/Documents/Cours/PhD/2A/Validation Blender model/Behave as the reality/Same model Simulation and Reality/Triangle pattern/3.5m/'
image_name = 'image name'
img_path = path + image_name
#Loading the image
img = bpy.data.images.load(img_path, check_existing=True)
#The image is put as the input of the node
image_node.image = img
#*****************Link nodes***************************
links = tree.links
#links.new(image_node.outputs[0], comp_node.inputs[0])
links.new(image_node.outputs[0], mix_node.inputs[1])
links.new(texture_node.outputs[1], mix_node.inputs[2])
links.new(mix_nodel.outputs[0], comp_node.inputs[0])
When I run my script I have on error on the creation of the mix and texture node. I check on the internet, and I found nothing. How can I fix that.
PS: I did not put the picture I am using. You can use one of yours.
'ShaderNodeGroup'
for creating mix while it should be'CompositorNodeMixRGB'
. And the same is with Texture, it should be'CompositorNodeImage'
if you need an Image Texture or'CompositorNodeTexture'
if you need a noise texture. You can find out proper names with Python Console autocomplete, they are detemined in.bl_idname
attribute of each node. $\endgroup$