2
$\begingroup$

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?

$\endgroup$
2
$\begingroup$

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 = bpy.data.node_groups.new('testGroup', 'ShaderNodeTree')
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.

$\endgroup$
4
$\begingroup$

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
$\endgroup$
  • 3
    $\begingroup$ 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. $\endgroup$ – ideasman42 Dec 9 '13 at 23:59
  • $\begingroup$ For some reason bpy.data.node_groups[-1] is not returning the last created node group. $\endgroup$ – gandalf3 Dec 10 '13 at 0:46
  • $\begingroup$ @gandalf3: many bpy collections are ordered alphabetically, so indices may change as you rename or add items. $\endgroup$ – CoDEmanX Dec 10 '13 at 8:13
  • $\begingroup$ @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. $\endgroup$ – gandalf3 Dec 10 '13 at 8:17
  • $\begingroup$ The last created node is made active is it not? $\endgroup$ – Greg Zaal Dec 10 '13 at 19:00

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.