# Custom Nodes Variables Not Being Stored

I am having an issue while working on a custom node tree. When I create a variable in self on a custom node it is not available in other functions of that class, for example:

from .base_node import  Base_Node
from bpy.types import Node

class Test_Node(Node, Base_Node):
bl_label = "Test Node"

def init(self, context):
self.outputs.new("tree_mesh_socket_type", "Tree")
self.inputs.new("tree_socket_type", "Tree In")
self.Test_Bool = False

def On_Execute(self):
print(self.Test_Bool)


I get the error:

line 14, in On_Execute
print(self.Test_Bool)
AttributeError: 'Test_Node' object has no attribute 'Test_Bool'


This happens where ever I define the variable, it is only accessible from the function it is created in.

Am I just misunderstanding how the node classes work or is this a bug? Should I be using a different method to store the data?

Thanks for any help.

• my 0.02c worth: Using TestNode and test_bool would IMO sit better with blenders API style convention. docs.blender.org/api/current/… – batFINGER Jun 17 at 13:50

You need to define it outside of the functions to make it a property of the class. Try adding something like the following before your 'def's :

class Test_Node(Node, Base_Node):
bl_label = "Test Node"

#Define class-level property
Test_Bool: bpy.props.BoolProperty()

def init(self, context):
.....etc.


This will define a new class-level property 'Test_Bool' and this should then be available as 'self.Test_Bool' from any of the functions within the class.

• Might be worth adding a few lines of code around that one line just to give a bit of context as to where, specifically, this line of code should be placed. – Ray Mairlot Jun 17 at 12:13
• How would that work for an instance of a class? As in  Class_Instance = My_Class("Example parameter") – Dragonpeak Jun 17 at 12:40
• Thanks@RayMairlot - good suggestion. – Rich Sedman Jun 17 at 12:43
• @Dragonpeak - I'm not sure, but it should work the same. The key is to define it at class level rather than within the function. Perhaps that would be a question more suited to a Python group rather than Blender. – Rich Sedman Jun 17 at 12:47
• @Dragonpeak It would be helpful if you could provide an example of your 'My_Class' situation. Perhaps ask a new question for that since the original one was specific to variables, not classes. – Rich Sedman Jun 17 at 14:23