7

Is it possible to create an Output Node with python? I tried to do it, but I'm in stuck.

Here is what I want to create:
example output node

This is the code I started but I'm sure it's wrong:

import bpy

bpy.context.area.type = 'NODE_EDITOR'
bpy.ops.node.add_node(use_transform=False, type="CompositorNodeOutputFile")
David
  • 49,291
  • 38
  • 159
  • 317
mifth
  • 2,341
  • 28
  • 36

2 Answers2

12

It's better to not use operators, there is a sophisticated "low-level" API for the node interface:

import bpy

scene = bpy.context.scene
nodes = scene.node_tree.nodes

render_layers = nodes['Render Layers']
output_file = nodes.new("CompositorNodeOutputFile")
output_file.base_path = "//maFolder/"

scene.node_tree.links.new(
    render_layers.outputs['Image'],
    output_file.inputs['Image']
)

You basically need to create a node and a link, and specify the input and output for the latter on creation to establish the connection.

CodeManX
  • 29,298
  • 3
  • 89
  • 128
  • 1
    This is great! Thank you! And how to create "set_01_", "set_02_", "set_03_".. outputs? – mifth Aug 11 '14 at 15:44
  • 1
    I asked a developer in charge and he replied: "the output file node is a horrible hack, everything is special there". So there's apparently no working low-level API. You can still use the operator from the panel (with an override if necessary). – CodeManX Aug 11 '14 at 17:45
7

Here is my result. Thank you a lot @Codemax.

output node and code in blender

import bpy

scene = bpy.context.scene
nodes = scene.node_tree.nodes

output_file = nodes.new("CompositorNodeOutputFile")
# output_file.base_path = "//maFolder/"

output_file.file_slots.remove(output_file.inputs[0])
for i in range(0, 20):
    idx = str(i + 1)
    if i < 9:
        idx = "0" + idx
    output_file.file_slots.new("set_" + idx)
David
  • 49,291
  • 38
  • 159
  • 317
mifth
  • 2,341
  • 28
  • 36