11
$\begingroup$

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.

$\endgroup$
18
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ the code fails me, could you post an example that works ? i itry to correct it myself but not sure what to type $\endgroup$ – user613326 Dec 9 '14 at 11:28
  • $\begingroup$ This example works for me, what error message do you get? $\endgroup$ – Jaroslav Jerryno Novotny Dec 9 '14 at 13:36
  • $\begingroup$ Python script fail, look in the console for now. But the console doesnt show anything so i'm puzzled. $\endgroup$ – user613326 Dec 11 '14 at 12:21
  • $\begingroup$ Its the System console: MainMenuBar > Window > ToggleSystemConsole $\endgroup$ – Jaroslav Jerryno Novotny Dec 11 '14 at 12:45
  • $\begingroup$ Aha it wants to load an image, from the location of the blend file; but it needs to use a fixed set path D:\BlenderTemp\myimage.jpg $\endgroup$ – user613326 Dec 11 '14 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.