Last active
July 23, 2018 23:30
-
-
Save IARI/fd9957b18689c2e1937233e4fcc284e0 to your computer and use it in GitHub Desktop.
Test Blender PYthon Nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bl_info = { | |
'name': 'Node Test', | |
'category': 'User', | |
'author': 'Julian Jarecki', | |
'blender': (2, 79, 0), | |
# 'location': 'File > Export', | |
'description': "Test custom Nodes and sockets", | |
} | |
import bpy | |
class MyNT(bpy.types.NodeTree): | |
""" This operator is only visible when Cycles is the selected render engine""" | |
bl_idname = "test_TNT" | |
bl_label = "Test Node Tree" | |
bl_icon = "QUESTION" | |
class Sock: | |
def draw(self, context, layout, node, x): | |
layout.label(self.name) | |
def draw_color(self, context, node): | |
return (1, 1, 1, 1) | |
class SockA(bpy.types.NodeSocket, Sock): | |
bl_idname = "test_sockA" | |
bl_label = "Socket A" | |
class SockB(bpy.types.NodeSocket, Sock): | |
bl_idname = "test_sockB" | |
bl_label = "Socket B" | |
class TestNode(bpy.types.Node): | |
bl_idname = "test_node" | |
bl_label = "Test Node" | |
def init(self, context): | |
self.inputs.new("test_sockA", "in A") | |
self.outputs.new("test_sockA", "out A") | |
self.inputs.new("test_sockB", "in B") | |
self.outputs.new("test_sockB", "out B") | |
def insertNode(layout, type, text, settings = {}, icon = "NONE"): | |
operator = layout.operator("node.add_node", text = text, icon = icon) | |
operator.type = type | |
operator.use_transform = True | |
for name, value in settings.items(): | |
item = operator.settings.add() | |
item.name = name | |
item.value = value | |
return operator | |
def drawMenu(self, context): | |
layout = self.layout | |
layout.operator_context = "INVOKE_DEFAULT" | |
insertNode(layout, "test_node", "Test Node") | |
types = [MyNT,SockA,SockB,TestNode] | |
def register(): | |
bpy.types.NODE_MT_add.append(drawMenu) | |
for t in types: | |
bpy.utils.register_class(t) | |
def unregister(): | |
bpy.types.NODE_MT_add.remove(drawMenu) | |
for t in types: | |
bpy.utils.unregister_class(t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment