Maybe someone can give me a little help. I’ve spent the last 10 days looking to this problem.
I found where the code is doing the creation of a Node Tree and why it doesn’t respect the bl_idname defined in the CustomNode class.
Im using my own compilation of Blender in Windows so I found it
# Custom node tree is edited as independent ID block
layout.template_ID(snode, "node_tree", new="node.new_node_tree")
The template_ID function doesnt allow to pass parameters to the node.new_node_tree operator.
I’ve tried everything I could thiink and couldn’t make it work with template_ID.
This will partially work (I’ve tested it):
layout.operator('node.new_node_tree', text='+ New').name = snode.tree_type
But loses the dropdown selector for trees due to the lack of template ID creating it.
In this same file, line 143 we can see how Geometry Nodes does it. And it is using a customized operator for it.
I kept digging in Blender Source Code and found the node.new_node_tree code operator in :
static int new_node_tree_exec(bContext *C, wmOperator *op)
The operator expects two properties ‘type’ and ‘name’.
If type is passed a value it searches for this type and uses it as the tree type of the new node tree.
If type has no value uses the Node Editor Space tree_idname as the tree type of the new node tree…
If name is passed a value uses it as the name of the of the new node tree.
If not uses and translates the string ‘NodeTree’.
And that is the problem.
The operator should check if the passed type, or the Node Editor Space tree_idname is one of the Blender internal types, including Geometry Nodes. Or if it’s any other type get the bl_idname property of the class if defined or the name class insted as the new tree name.
What kind of modification will be better so it can be accepted as a patch?
- Do the change on this operator.
- Modify the space_node.py to search for a new operator called ‘node.new_’ + CustomNode.bl_idname or the CustomNode.class if bl_idname is not defined.
This option will force that the CustomNodes template show how to create such operator.
I will try to locate the authors of other CustomNodes addons and point them here so the can give their opinon.