3
$\begingroup$

I'm trying to use python to create nodes in the compositor. Right now I want to create an ID Mask node, but there will eventually be others.

If I create an ID Mask node via the UI and ask the python console what is C.scene.node_tree.nodes.active.type it tells me 'ID_MASK', but if I C.scene.node_tree.nodes.new('ID_MASK') I get an error

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
RuntimeError: Error: Node type ID_MASK undefined

How do I learn the proper values for the type parameter for node_tree.nodes.new(type) ?

$\endgroup$

3 Answers 3

3
$\begingroup$

The correct type for this would be: 'CompositorNodeIDMask'.

Too create a new ID Mask node the line would be : C.scene.node_tree.nodes.new('CompositorNodeIDMask')

If this is confusing, at least they have a pattern so you have 'CompositorNode'or'ShaderNode'or'TextureNode' plus the node type like 'ShaderNode'+'ObjectInfo'.

For the full list of node types see these links: shader nodes, compositor nodes and texture nodes

$\endgroup$
1
  • $\begingroup$ It turns out those links are not the FULL list. There are things like NodeReroute too. $\endgroup$
    – Mutant Bob
    Aug 11, 2015 at 16:13
1
$\begingroup$

type(bpy.context.scene.node_tree.nodes.active)

class 'bpy.types.CompositorNodeIDMask'

import bpy
ntype = str(type(bpy.context.scene.node_tree.nodes.active))
nodetype = ntype.rsplit('.')[2][:-2]
print (nodetype)
$\endgroup$
0
1
$\begingroup$

Since 2.68 the API doc for Nodes.new(type) states "Type of node to add (Warning: should be same as node.bl_idname, not node.type!)"

>>> [n.bl_idname for n in D.materials['Material'].node_tree.nodes]
['ShaderNodeOutputMaterial', 'ShaderNodeBsdfDiffuse', 'NodeReroute']
$\endgroup$

You must log in to answer this question.

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