7
$\begingroup$

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")
$\endgroup$

2 Answers 2

12
$\begingroup$

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.

$\endgroup$
2
  • 1
    $\begingroup$ This is great! Thank you! And how to create "set_01_", "set_02_", "set_03_".. outputs? $\endgroup$
    – mifth
    Commented Aug 11, 2014 at 15:44
  • 1
    $\begingroup$ 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). $\endgroup$
    – CodeManX
    Commented Aug 11, 2014 at 17:45
7
$\begingroup$

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)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .