1
$\begingroup$

I often find myself looking for certain types of nodes inside my node trees. I'd like to be able to set their color to a bright yellow so I can see all of them at a glance.

How can I do that ?

$\endgroup$

1 Answer 1

3
$\begingroup$

I wrote a self contained script that can easily be turned into an add-on. This will add an operator in the toolshelf of all the node editors. Then you just have to click on the operator to run it. It will display a popup where you can change the node type, the desired color and whether you want to select nodes after the operation.

If a node is active when the operator is run, it will be suggested as the default type.

Note that it works in any node tree. It should be working in custom node trees generated by add-ons too though I didn't test it.

Proof by example :

enter image description here

import bpy
from bpy.props import EnumProperty, FloatVectorProperty, BoolProperty


def get_active_node_tree(context):
    node_area = context.area if context.area.type == "NODE_EDITOR" else None
    if node_area is None:
        return
    return node_area.spaces[0].edit_tree


def get_node_types(_, context):
    node_types = set()
    for node in get_active_node_tree(context).nodes:
        node_types.add(node.type)
    node_types = list(node_types)
    node_types.sort()
    return [(node_type,) * 3 for node_type in node_types]


class NODES_OT_color_by_type(bpy.types.Operator):
    bl_idname = "nodes.color_by_type"
    bl_label = "Color all nodes of a given type"
    bl_options = {"UNDO", "REGISTER"}

    @classmethod
    def poll(cls, context):
        return get_active_node_tree(context) is not None

    node_type: EnumProperty(name="Type", items=get_node_types)
    node_color: FloatVectorProperty(name="Color", subtype="COLOR", min=0, max=1, default=(0.5, 0.5, 0.5))
    select_nodes: BoolProperty(name="Select nodes after operation", default=False)

    def invoke(self, context, event):
        if context.active_node is not None:
            self.node_type = context.active_node.type
        return context.window_manager.invoke_props_dialog(self)

    def execute(self, context):
        node_type = self.node_type
        for node in get_active_node_tree(context).nodes:
            if node.type == node_type:
                node.use_custom_color = True
                node.color = self.node_color
                if self.select_nodes:
                    node.select = True

        return {"FINISHED"}


class GU_PT_node_editor_qol(bpy.types.Panel):
    bl_space_type = "NODE_EDITOR"
    bl_label = "QOL"
    bl_region_type = "UI"
    bl_category = "Tool"

    def draw(self, context):
        self.layout.operator(NODES_OT_color_by_type.bl_idname)


if __name__ == "__main__":
    bpy.utils.register_class(NODES_OT_color_by_type)
    bpy.utils.register_class(GU_PT_node_editor_qol)

Link to a nice ressource for the task at hand.

$\endgroup$
8
  • $\begingroup$ very nice...although the yellow burned down my eyes.... ;) +1 +2, if you change to cyan :D $\endgroup$
    – Chris
    Mar 12, 2022 at 15:39
  • 1
    $\begingroup$ @Chris Yeah I settled for a less saturated green afterwards ^^ white on yellow is not readable at ALL $\endgroup$
    – Gorgious
    Mar 12, 2022 at 16:23
  • $\begingroup$ This would be a good addon to use presets $\endgroup$ Mar 12, 2022 at 16:47
  • 1
    $\begingroup$ @MartyFouts hehe nice thanks for the credit :) Funny I maintain the same type of addon for my day to day use. github.com/Gorgious56/gorgious_utilities Totally undocumented though >< Cheers $\endgroup$
    – Gorgious
    Mar 13, 2022 at 20:16
  • 1
    $\begingroup$ @Gorgious If you've got the time there's a bpy specific discord that I think would love to have you. $\endgroup$ Mar 13, 2022 at 20:27

You must log in to answer this question.

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