Custom python nodes, "link" node tree with object?

Hi, I was testing the custom node script that the text editor have as example. After a while I get realized that the custom node tree uses the nodes globally, I mean that it doesn’t care if you have one or another object selected, the node tree is the same for every object, like the composition tree.

Material nodes are “linked” to some material, while the texture nodes are linked with textures. Is it possible to create custom node in that manner? but in this case I want it to be linked to objects, and how?

This is an example script, what do I have to change?, is a simplification of the default custom node script:

import bpy
from bpy.types import NodeTree, Node, NodeSocket

class exampleTree(NodeTree):
    bl_idname = 'exampleTree'
    bl_label = 'Example node tree'
    bl_icon = 'GAME'
class exampleTreeNode:
    def poll(cls, ntree):
        return ntree.bl_idname == 'exampleTree'

class exampleNode(Node, exampleTreeNode):
    bl_idname = 'exampleNode'
    bl_label = 'Node'
    bl_icon = 'GAME'

    def init(self, context):'NodeSocketFloat', "Input")'NodeSocketFloat', "Output")

import nodeitems_utils
from nodeitems_utils import NodeCategory, NodeItem

class MyNodeCategory(NodeCategory):
    def poll(cls, context):
        return context.space_data.tree_type == 'exampleTree'

node_categories = [
    MyNodeCategory("exampleNodes", "Nodes", items=[

def register():

        nodeitems_utils.register_node_categories("CUSTOM_NODES", node_categories)
        nodeitems_utils.register_node_categories("CUSTOM_NODES", node_categories)

def unregister():


if __name__ == "__main__":
1 Like

hi, i know this thread is old, but i am trying to start a custom nodetree addon, and not being a coder, it s hard to get specific doc on that topic ! did you manage to get your custom nodetree type working ? did you find good help or doc on that subject ? thx ! cheers