Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bl_info = {"name": "Test2.8", "category": "Node"}
- import bpy
- import nodeitems_utils
- class CustomNodeTree(bpy.types.NodeTree):
- """Custom Node Tree"""
- bl_idname = "CustomNodeTree"
- bl_label = "Custom Node Tree"
- bl_icon = "NODETREE"
- @classmethod
- def poll(tree_class, context):
- return True
- # class CustomProperty(bpy.types.PropertyGroup):
- # pass
- # class CustomSocket(byp.types.NodeSocket):
- # pass
- class CustomNode(bpy.types.Node, CustomNodeTree):
- """Custom Node"""
- bl_idname = "CustomNode"
- bl_label = "Custom Node"
- bl_icon = "OBJECT_DATA"
- color: bpy.props.FloatVectorProperty(name="color", size=4, subtype='COLOR')
- # socket_value_update(context)
- # Update after property changes
- def socket_value_update(self, context):
- print(str(self) + ": socket_value_update")
- def read_input(self, name):
- if name not in self.inputs:
- return None
- for link in self.inputs[name].links:
- if link.is_valid:
- return link.from_socket.default_value
- return self.inputs[name].default_value
- # update()
- # Update on editor changes
- def update(self):
- print(str(self) + ": update")
- self.color = self.read_input("Input")
- self.outputs["Output"].default_value = self.color
- print(str(self.inputs["Input"]))
- print(str(self.color))
- print(str(self.outputs["Output"]))
- # init(context)
- # Initialize a new instance of this node
- def init(self, context):
- print("init")
- self.inputs.new("NodeSocketColor", "Input")
- self.outputs.new("NodeSocketColor", "Output")
- # copy(node)
- # Initialize a new instance of this node from an existing node
- # Parameters: node (Node, (never None)) - Node, Existing node to copy
- def copy(self, node):
- print(str(self) + ": copy from " + str(node))
- self.inputs["Input"].default_value = node.inputs["Input"].default_value
- self.color = node.color
- # draw_buttons(context, layout)
- # Draw node buttons
- # Parameters: layout (UILayout, (never None)) - Layout, Layout in the UI
- def draw_buttons(self, context, layout):
- layout.prop(self, "color")
- # draw_buttons_ext(context, layout)
- # Draw node buttons in the sidebar
- # Parameters: layout (UILayout, (never None)) - Layout, Layout in the UI
- def draw_buttons_ext(self, context, layout):
- layout.prop(self, "color")
- # draw_label()
- # Returns a dynamic label string
- # Returns: Label
- # Return type: string, (never None)
- def draw_label(self):
- return "Custom Node"
- @classmethod
- def poll(node_class, context):
- return True
- class CustomNodeCategory(nodeitems_utils.NodeCategory):
- @classmethod
- def poll(category_class, context):
- return True
- node_categories = [
- CustomNodeCategory(
- "CUSTOM",
- "Custom",
- items = [
- nodeitems_utils.NodeItem("CustomNode")
- ]
- )
- ]
- registered = False
- classes = (
- CustomNodeTree,
- CustomNode,
- )
- class_reg, class_unreg = bpy.utils.register_classes_factory(classes)
- def register():
- class_reg()
- nodeitems_utils.register_node_categories("CUSTOM", node_categories)
- registered = True
- def unregister():
- try:
- nodeitems_utils.unregister_node_categories("CUSTOM")
- except:
- print("Failed to unregister CUSTOM")
- class_unreg()
- registered = False
- if __name__ == "__main__":
- print("\n")
- try:
- unregister()
- except:
- print("Failed to unregister")
- # try:
- # register()
- # except:
- # print("Failed to register")
- register()
Advertisement
Add Comment
Please, Sign In to add comment