Hi All,
With pynodes on the horizon for the next release I thought I would try to get some kind of example code working to leverage this new feature.
I copied this code from the developers pagehere.
import bpy
#http://wiki.blender.org/index.php/User:Phonybone/Python_Nodes
from bpy.props import PointerProperty, StringProperty, BoolProperty, EnumProperty, \
IntProperty, FloatProperty, FloatVectorProperty, CollectionProperty
class MyCustomNode(bpy.types.Node):
# Description string
'''A custom node'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'CustomNodeType'
# Label for nice name display
bl_label = 'Custom Node'
# Icon identifier
bl_icon = 'SOUND'
# File path property stored in the node
myStringProperty = bpy.props.StringProperty(subtype='FILE_PATH', default="//")
# Custom enum property to select from a predefined list
my_items = [
("DOWN", "Down", "Where your feet are"),
("UP", "Up", "Where your head should be"),
("LEFT", "Left", "Not right"),
("RIGHT", "Right", "Not left")
]
myEnumProperty = bpy.props.EnumProperty(name="Direction", description="Just an example", items=my_items, default='UP')
# the input value property to use for an unconnected socket
my_input_value = bpy.props.FloatProperty(name="Size", default=5.0, subtype="FACTOR")
@classmethod
def poll(cls, tree):
# this node is only available in trees of the 'CustomTreeType'
return tree.bl_idname == 'CustomTreeType'
def poll_instance(self, tree):
return True
def init(self, context):
print("New node: ", self.name)
#my_input = self.inputs.new("NodeSocketFloat", "My Input")
#my_input.value_property = "my_input_value"
def copy(self, node):
print("New node ", self.name, "copied from", node.name)
def free(self):
print("Removing node: ", self.name)
def update(self):
print("Updating node: ", self.name)
def draw_buttons(self, context, layout):
layout.prop(self, "myStringProperty")
layout.prop(self, "myEnumProperty")
def draw_buttons_ext(self, context, layout):
layout.label("These are extended node options")
layout.prop(self, "myStringProperty")
layout.prop(self, "myEnumProperty")
layout.operator("node.my_custom_operator")
class MyCustomSocket(bpy.types.NodeSocket):
# Description string
'''Custom node socket type'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'CustomSocketType'
# Label for nice name display
bl_label = 'Custom Node Socket'
# Socket color
bl_color = (1.0, 0.4, 0.216, 0.5)
class MyCustomTree(bpy.types.NodeTree):
# Description string
'''A custom node tree type that will show up in the node editor header'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'CustomTreeType'
# Label for nice name display
bl_label = 'Custom Node Tree'
# Icon identifier
# Note: If no icon is defined, the node tree will not show up in the editor header!
# This can be used to make additional tree types for groups and similar nodes
bl_icon = 'NODETREE'
@classmethod
def poll(cls, context):
# typical shader node test for compatible render engine setting
return context.scene.render.engine == 'Cycles'
bpy.utils.register_class(MyCustomNode)
The code does run and the class registers, but no new Node appears in the list to add to the Node window.
Does anyone know how to get this working so my new custom node will show up and work?