2
$\begingroup$

So I was making node groups the other day, and had a thought... "Hey, could I put these into one of blender's premade categories?" I searched far and wide, climbed mountains, ventured across multiple landscapes, but found no answer. So what I want to do, is put these node groups into the default blender categories, or possibly make my own category. I do not want to go into "Group" every time. How can I do this?

$\endgroup$
6
  • $\begingroup$ AFAIK Can only be done using python and I guess that isn't worth it ... $\endgroup$
    – brockmann
    Apr 13, 2021 at 21:18
  • $\begingroup$ Well I would like to know how to do it, even if it's a little complicated. $\endgroup$ Apr 13, 2021 at 21:19
  • $\begingroup$ @Zany_Zachary1 you'll need to override some functions of nodeitems_utils and nodeitems_builtins modules. It's not a simple thing but it's possible. $\endgroup$
    – Secrop
    Apr 14, 2021 at 7:05
  • $\begingroup$ only batFinger can help here... ;) $\endgroup$
    – Chris
    Apr 14, 2021 at 7:17
  • $\begingroup$ batFinger the GitHubber? Also, I'm a total noob at coding, so I'll probably not modify any modules or anything. $\endgroup$ Apr 14, 2021 at 12:41

1 Answer 1

4
$\begingroup$

The simplest way to do it is using a python script.


First thing to do is to changing your node group name to have a '.' at the start, i.e: myXptoNodeGroup >> .myXptoNodeGroup. This way, the nodegroup will no longer appear in the "Group" menu.

The second thing to do is editing the following script by adding your nodegroup(s) to the items list of the ShaderNodeCategory instead of '.myXptoNodeGroup', and run the script:

import bpy
from nodeitems_utils import register_node_categories, unregister_node_categories, NodeItem
from nodeitems_builtins import ShaderNodeCategory

node_categories = [
    ShaderNodeCategory('SOMENODES', "Some Nodes", items=[
        NodeItem('ShaderNodeGroup', "myXptoNodeGroup", {"node_tree": "bpy.data.node_groups['.myXptoNodeGroup']"} ),
    ]),
]

def register():
    register_node_categories('MYGROUPNODES', node_categories)


def unregister():
    unregister_node_categories('MYGROUPNODES')


if __name__ == "__main__":
    register()

Of course, this is not exclusive to ShaderNodeGroups, it's just a matter to change the corresponding NodeCategory, and the NodeGroup type for the NodeItem.

$\endgroup$
7
  • $\begingroup$ This is great!!! Is there any way that I can reorder it, to put it above the "Textures" Category? $\endgroup$ Apr 14, 2021 at 18:11
  • $\begingroup$ Humm.. yes there is, but it's a bit hidden... The order of shadernodes is stored in a list inside the _node_categories in the nodeitems_utils module... in there you can use L.insert(3, L.pop()) right after registering.. (3 is the index of the TextureCategory, and L=nodeitems_utils._node_categories['SHADER'][0]) $\endgroup$
    – Secrop
    Apr 14, 2021 at 18:37
  • $\begingroup$ So I tried to add that, right after the registration, and it broke the addon. I deleted it, and it still didn't install. I guess it isn't really a big deal though, I'll just remake the addon. $\endgroup$ Apr 15, 2021 at 13:00
  • $\begingroup$ I know why, but it's difficult to explain it in just a small comment.. If you can digest the structure of the _nodes_categories dictionary, and how the draw_node_categories_menu calls each category, you'll find that your nodes aren't stored in the same place where builtin nodes are. It's quite tricky to change this without breaking everything (though it's surely possible to do it). $\endgroup$
    – Secrop
    Apr 15, 2021 at 13:25
  • $\begingroup$ I've written some functions that manipulate the _node_categories directly, that you can also take a look; though I don't advise you to use them without understanding what each line of code does.. You could check [github.com/Secrop/ShaderNodesExtra2.80/blob/master/__init__.py] , specially the addCat and delCat functions in the end of that file $\endgroup$
    – Secrop
    Apr 15, 2021 at 13:38

You must log in to answer this question.

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