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 ?
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 :
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.