How to specify the name of a node group when creating it from python?

I have been creating node groups with the group_make operator, but there doesn't seem to be any way to set properties such as the label or name of the resulting group node.

This makes it difficult to access this node later, and be sure that one is accessing the correct node.

How can I specify node properties on creation?

The problem with using operators in scripts is they return {FINISHED} rather than the object you wish to keep working with. Instead of using the make_group operator you could use

import bpy

test_group.name = 'anotherGroupName'


node_groups.new() creates the group with the name set to the first pramater. The result returned into test_group can be used later to change that name.

You can also reference the group by name to change it.

bpy.data.node_groups['testgrp'].name = 'NewGroupName'


but without knowing the auto-generated name from the operator this isn't helpful.

You can use something like this:

node_grp = bpy.data.node_groups[-1] # to get last created group
node_grp.name = "Special Name" # to set a name

• Its really bad practice to assume this kind of stuff (the position in a sequence of newly added data), that said, it does work and is unlikely to break any time soon. Ideally you would create the group using bpy.data.node_groups.new(name, type) but realize there may be cases where this isnt a drop-in replacement. – ideasman42 Dec 9 '13 at 23:59
• For some reason bpy.data.node_groups[-1] is not returning the last created node group. – gandalf3 Dec 10 '13 at 0:46
• @gandalf3: many bpy collections are ordered alphabetically, so indices may change as you rename or add items. – CodeManX Dec 10 '13 at 8:13
• @ideasman42 bpy.data.node_groups.new works for me, thanks. @CoDEmanX I assigned the variable right after creating the nodegroup, but it still wasn't the right nodegroup. – gandalf3 Dec 10 '13 at 8:17
• The last created node is made active is it not? – Greg Zaal Dec 10 '13 at 19:00