Skip to content

Instantly share code, notes, and snippets.

@OEP
Last active January 24, 2024 08:27
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save OEP/5978445 to your computer and use it in GitHub Desktop.
Save OEP/5978445 to your computer and use it in GitHub Desktop.
Basic script for Blender Python nodes
import bpy
from bpy.props import IntProperty, FloatProperty, PointerProperty
import nodeitems_utils
from nodeitems_utils import NodeItem, NodeCategory
bl_info = {
"name": "Custom nodes",
"category": "Node",
}
class CustomPropertyGroup(bpy.types.PropertyGroup):
int_value = IntProperty()
float_value = FloatProperty()
def draw(self, context, layout):
row = layout.row()
row.prop(self, "int_value")
row = layout.row()
row.prop(self, "float_value")
class CustomPanel(bpy.types.Panel):
bl_idname = "CustomPanel"
bl_label = "Custom Panel"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "render"
@classmethod
def poll(cls, context):
return True
def draw(self, context):
context.scene.custom_properties.draw(context, self.layout)
class CustomNodeTree(bpy.types.NodeTree):
bl_description = "Custom Node Trees"
bl_icon = "MESH_TORUS"
bl_idname = "CustomNodeTree"
bl_label = "Custom node tree"
class CustomNodeSocket(bpy.types.NodeSocket):
bl_idname = "CustomNodeSocket"
bl_label = "Custom Node Socket"
def draw(self, context, layout, node, x):
layout.label(self.name)
def draw_color(self, context, node):
return (1,1,1,1)
class CustomNode(bpy.types.Node):
bl_idname = "CustomNode"
bl_label = "Custom Node"
custom_properties = PointerProperty(type=CustomPropertyGroup)
def init(self, context):
self.inputs.new("CustomNodeSocket", "in")
self.outputs.new("CustomNodeSocket", "out")
def draw_buttons(self, context, layout):
self.custom_properties.draw(context, layout)
class CustomNodeCategory(NodeCategory):
@classmethod
def poll(cls, context):
return context.space_data.tree_type == "CustomNodeTree"
categories = [
CustomNodeCategory("CUSTOM_CATEGORY", "Category", items = [
NodeItem("CustomNode"),
]),
]
def register():
bpy.utils.register_class(CustomNodeTree)
bpy.utils.register_class(CustomNodeSocket)
bpy.utils.register_class(CustomPropertyGroup)
bpy.utils.register_class(CustomPanel)
bpy.utils.register_class(CustomNode)
bpy.types.Scene.custom_properties = PointerProperty(type=CustomPropertyGroup)
nodeitems_utils.register_node_categories("CUSTOM_CATEGORIES", categories)
def unregister():
bpy.utils.unregister_class(CustomNodeTree)
bpy.utils.unregister_class(CustomNodeSocket)
bpy.utils.unregister_class(CustomPropertyGroup)
bpy.utils.unregister_class(CustomPanel)
bpy.utils.unregister_class(CustomNode)
del bpy.types.Scene.custom_properties
nodeitems_utils.unregister_node_categories("CUSTOM_CATEGORIES")
@IARI
Copy link

IARI commented Jul 19, 2018

Where does this nodeitem_utils come from?

@iliis
Copy link

iliis commented Jun 15, 2021

Where does this nodeitem_utils come from?

This seems to be built-in in Blender itself. With Blender 2.92.0 I can run this script as-is and it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment