Advertisement
Guest User

CustomNodeGroupTemplate

a guest
Feb 17th, 2020
1,780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1. import bpy
  2.  
  3.  
  4. class NODE_PT_MAINPANEL(bpy.types.Panel):
  5.     bl_label = "Custom Node Group"
  6.     bl_idname = "NODE_PT_MAINPANEL"
  7.     bl_space_type = 'NODE_EDITOR'
  8.     bl_region_type = 'UI'
  9.     bl_category = 'New Tab'
  10.  
  11.     def draw(self, context):
  12.         layout = self.layout
  13.  
  14.         row = layout.row()
  15.         row.operator('node.test_operator')
  16.  
  17.  
  18.  
  19.  
  20.  
  21. def create_test_group(context, operator, group_name):
  22.    
  23.         #enable use nodes
  24.     bpy.context.scene.use_nodes = True
  25.    
  26.     test_group = bpy.data.node_groups.new(group_name, 'CompositorNodeTree')
  27.    
  28.     group_in = test_group.nodes.new('NodeGroupInput')
  29.     group_in.location = (-200,0)
  30.     test_group.inputs.new('NodeSocketFloat','Factor Value') #0
  31.     test_group.inputs.new('NodeSocketColor','Color Input') #1
  32.    
  33.    
  34.     group_out = test_group.nodes.new('NodeGroupOutput')
  35.     group_out.location = (400,0)
  36.     test_group.outputs.new('NodeSocketColor','Output')
  37.    
  38.    
  39.     mask_node = test_group.nodes.new(type= 'CompositorNodeBoxMask')
  40.     mask_node.location = (0,0)
  41.     mask_node.rotation = 1
  42.    
  43.     mix_node = test_group.nodes.new(type= 'CompositorNodeMixRGB')
  44.     mix_node.location = (200,0)
  45.     mix_node.use_clamp = True
  46.     mix_node.blend_type = 'OVERLAY'
  47.    
  48.    
  49.     link = test_group.links.new
  50.    
  51.     link(mask_node.outputs[0], mix_node.inputs[1])
  52.    
  53.     link(group_in.outputs[0], mix_node.inputs[0])
  54.     link(group_in.outputs[1], mix_node.inputs[2])
  55.    
  56.     link(mix_node.outputs[0], group_out.inputs[0])
  57.    
  58.     return test_group
  59.    
  60.    
  61.  
  62.  
  63.            
  64. class NODE_OT_TEST(bpy.types.Operator):
  65.     bl_label = "Add Custom Node Group"
  66.     bl_idname = "node.test_operator"
  67.    
  68.     def execute(self, context):
  69.        
  70.         custom_node_name = "Test Node"
  71.         my_group = create_test_group(self, context, custom_node_name)
  72.         test_node = context.scene.node_tree.nodes.new('CompositorNodeGroup')
  73.         test_node.node_tree = bpy.data.node_groups[my_group.name]
  74.         test_node.use_custom_color = True
  75.         test_node.color = (0.5, 0.4, 0.3)
  76.        
  77.         return {'FINISHED'}
  78.            
  79.    
  80.    
  81.    
  82.    
  83. def register():
  84.     bpy.utils.register_class(NODE_PT_MAINPANEL)
  85.     bpy.utils.register_class(NODE_OT_TEST)
  86.    
  87.    
  88.    
  89.  
  90.  
  91. def unregister():
  92.     bpy.utils.unregister_class(NODE_PT_MAINPANEL)
  93.     bpy.utils.unregister_class(NODE_OT_TEST)
  94.  
  95.  
  96. if __name__ == "__main__":
  97.     register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement