[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57301] trunk/blender/release/scripts/ templates_py/custom_nodes.py: Added an example for using the new node categories system to the custom_nodes .py template script.

Lukas Toenne lukas.toenne at googlemail.com
Sun Jun 9 10:46:49 CEST 2013


Revision: 57301
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57301
Author:   lukastoenne
Date:     2013-06-09 08:46:48 +0000 (Sun, 09 Jun 2013)
Log Message:
-----------
Added an example for using the new node categories system to the custom_nodes.py template script.

Modified Paths:
--------------
    trunk/blender/release/scripts/templates_py/custom_nodes.py

Modified: trunk/blender/release/scripts/templates_py/custom_nodes.py
===================================================================
--- trunk/blender/release/scripts/templates_py/custom_nodes.py	2013-06-09 08:46:47 UTC (rev 57300)
+++ trunk/blender/release/scripts/templates_py/custom_nodes.py	2013-06-09 08:46:48 UTC (rev 57301)
@@ -120,17 +120,56 @@
         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():
     bpy.utils.register_class(MyCustomTree)
     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)




More information about the Bf-blender-cvs mailing list