Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Toenne <lukas.toenne@googlemail.com>2013-06-09 12:46:48 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2013-06-09 12:46:48 +0400
commit90cbf5d5918f770a6a348d84a8601f93c33ace22 (patch)
tree315f20b547a9bdfbd0374bb2dab13f9b7b0f3e50 /release
parentfd2e3999bbbac2569e477eeb4eae1e261d1f4e36 (diff)
Added an example for using the new node categories system to the custom_nodes.py template script.
Diffstat (limited to 'release')
-rw-r--r--release/scripts/templates_py/custom_nodes.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/release/scripts/templates_py/custom_nodes.py b/release/scripts/templates_py/custom_nodes.py
index 6d5f85a556c..30c91840590 100644
--- a/release/scripts/templates_py/custom_nodes.py
+++ b/release/scripts/templates_py/custom_nodes.py
@@ -120,8 +120,43 @@ class MyCustomNode(bpy.types.Node, MyCustomTreeNode):
layout.prop(self, "myStringProperty")
+### Node Categories ###
+# Node categories are a python system for automatically
+# extending the Add menu, toolbar panels and search operator.
+# For more examples see release/scripts/startup/nodeitems_builtins.py
+import nodeitems_utils
+from nodeitems_utils import NodeCategory, NodeItem
+# our own base class with an appropriate poll function,
+# so the categories only show up in our own tree type
+class MyNodeCategory(NodeCategory):
+ @classmethod
+ def poll(cls, context):
+ return context.space_data.tree_type == 'CustomTreeType'
+
+# all categories in a list
+node_categories = [
+ # identifier, label, items list
+ MyNodeCategory("SOMENODES", "Some Nodes", items=[
+ # our basic node
+ NodeItem("CustomNodeType"),
+ ]),
+ MyNodeCategory("OTHERNODES", "Other Nodes", items=[
+ # the node item can have additional settings,
+ # which are applied to new nodes
+ # NB: settings values are stored as string expressions,
+ # for this reason they should be converted to strings using repr()
+ NodeItem("CustomNodeType", label="Node A", settings={
+ "myStringProperty" : repr("Lorem ipsum dolor sit amet"),
+ "myFloatProperty" : repr(1.0),
+ }),
+ NodeItem("CustomNodeType", label="Node B", settings={
+ "myStringProperty" : repr("consectetur adipisicing elit"),
+ "myFloatProperty" : repr(2.0),
+ }),
+ ]),
+ ]
def register():
@@ -129,8 +164,12 @@ def register():
bpy.utils.register_class(MyCustomSocket)
bpy.utils.register_class(MyCustomNode)
+ nodeitems_utils.register_node_categories("CUSTOM_NODES", node_categories)
+
def unregister():
+ nodeitems_utils.unregister_node_categories("CUSTOM_NODES")
+
bpy.utils.unregister_class(MyCustomTree)
bpy.utils.unregister_class(MyCustomSocket)
bpy.utils.unregister_class(MyCustomNode)