19

I've been looking at the python code loging of Blender. But in there things get loged as mouse clicks.

What i like to do is combine a few images into a larger one using compositor, but i need control over compositor by python script. The problem seams to me that it is a bit hard to "spawn" a few nodes, set their values and connect them.

I need an micture of: image, scale, source image location, mix nodes, output nodes

I have no Code samples other then the log of blender python which in this case is of no big help.

user613326
  • 426
  • 1
  • 6
  • 18

1 Answers1

40

A simple code example:

# switch on nodes and get reference
bpy.context.scene.use_nodes = True
tree = bpy.context.scene.node_tree

# clear default nodes
for node in tree.nodes:
    tree.nodes.remove(node)

# create input image node
image_node = tree.nodes.new(type='CompositorNodeImage')
image_node.image = bpy.data.images['YOUR_IMAGE_NAME']
image_node.location = 0,0

# create output node
comp_node = tree.nodes.new('CompositorNodeComposite')   
comp_node.location = 400,0

# link nodes
links = tree.links
link = links.new(image_node.outputs[0], comp_node.inputs[0])

Here are node types you can create:
Nodes subclasses API

If you need anything more let me know.

p2or
  • 15,860
  • 10
  • 83
  • 143
Jaroslav Jerryno Novotny
  • 51,077
  • 7
  • 129
  • 218