-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtools_nodes_ops.py
74 lines (61 loc) · 2.29 KB
/
tools_nodes_ops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Nikita Akimov
#
# GitHub
# https://github.com/Korchy/BIS
import bpy
from bpy.types import Operator, PropertyGroup, WindowManager
from bpy.props import PointerProperty, StringProperty
from bpy.utils import register_class, unregister_class
from .node_manager import NodeManager
from .tools_nodes import NodesTools
class BIS_OT_tools_nodes_add_node_group_io(Operator):
bl_idname = 'bis.tools_nodes_add_node_group_io'
bl_label = 'Add input/output'
bl_description = 'Add input/output to active node group'
bl_options = {'REGISTER', 'UNDO'}
in_out: StringProperty(
name='IN_OUT',
default='IN'
)
def execute(self, context):
active_node = NodeManager.active_node(context=context)
if self.in_out == 'IN':
NodesTools.add_input_to_node(
node=active_node,
input_type=context.window_manager.bis_tools_nodes_vars.io_type,
input_name='input'
)
elif self.in_out == 'OUT':
NodesTools.add_output_to_node(
node=active_node,
output_type=context.window_manager.bis_tools_nodes_vars.io_type,
output_name='output'
)
return {'FINISHED'}
@classmethod
def poll(cls, context):
if context.active_object:
active_node = NodeManager.active_node(context=context)
if active_node and active_node.select and active_node.type == 'GROUP':
return True
return False
class BISNodesToolsVars(PropertyGroup):
io_type: bpy.props.EnumProperty(
items=[
('NodeSocketInt', 'Int', 'Int', '', 0),
('NodeSocketFloat', 'Float', 'Float', '', 1),
('NodeSocketColor', 'Color', 'Color', '', 2),
('NodeSocketVector', 'Vector', 'Vector', '', 3),
('NodeSocketShader', 'BSDF', 'Shader', '', 4)
],
default='NodeSocketInt'
)
def register():
register_class(BIS_OT_tools_nodes_add_node_group_io)
register_class(BISNodesToolsVars)
WindowManager.bis_tools_nodes_vars = PointerProperty(type=BISNodesToolsVars)
def unregister():
del WindowManager.bis_tools_nodes_vars
unregister_class(BISNodesToolsVars)
unregister_class(BIS_OT_tools_nodes_add_node_group_io)