-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
211 lines (155 loc) · 5.75 KB
/
__init__.py
File metadata and controls
211 lines (155 loc) · 5.75 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import bpy
bl_info = {
"name": "Display Local Nodes",
"description": "Adds a display in your Node Editor, to show local nodes, in the Tool section.",
"author": "RonboPrime",
"email":"ronboprime@gmail.com",
"version": (1, 5),
"blender": (4,0,0),
"location": "Node Editor> Navigation Bar> Tool",
"warning": "",
"doc_url": "",
"tracker_url": "",
"category": "Node",
}
class NODE_OT_add_node_group(bpy.types.Operator):
bl_idname = "node_ot.add_node_group"
bl_label = "Add Node Group"
bl_options={"REGISTER","UNDO"}
# Property to hold the name of the node group to add
node_group_name: bpy.props.StringProperty()
def execute(self, context):
#sanity check
obj=bpy.context.active_object
print(obj.name)
#is this thing on?
if obj==None:
self.report({'WARNING'},"How can you have any node tree, if you don't have your active object!")
return{"CANCELLED"}
# Get the node groups
node_groups = bpy.data.node_groups
# Get the active node tree
node_tree = context.space_data.node_tree
print(node_tree.name)
# what if there's no node tree?
try:
# Create a new group node
new_node = node_tree.nodes.new(type='GeometryNodeGroup')
# Set the node group of the new node
if node_tree.name!=self.node_group_name:
new_node.node_tree = bpy.data.node_groups[self.node_group_name]
new_node.location = (420, 420)
else:
return {'FINISHED'}
# Handled.
except AttributeError:
self.report({'WARNING'}, "No active node tree found... Good heavens, fix your life man!")
return {'CANCELLED'}
return {"FINISHED"}
class NODE_PT_my_panel(bpy.types.Panel):
bl_idname="NODE_PT_panel"
bl_label = "Local Node Groups"
bl_space_type = 'NODE_EDITOR'
bl_region_type = 'UI'
bl_category = "Tool"
def draw(self, context):
# specify the node tree
node_tree=context.space_data.node_tree
# Get the node groups
node_groups=bpy.data.node_groups
# Initialize the UI
col = self.layout.column(align=True)
# Iterate over node groups
for ng in bpy.data.node_groups:
# Create a button for the node group
if ng.name != node_tree.name:
op = col.operator("node_ot.add_node_group", text=ng.name,icon="KEYTYPE_JITTER_VEC")
# Set the operator's node_group_name property
op.node_group_name = ng.name
#Registration
classes=[NODE_PT_my_panel, NODE_OT_add_node_group]
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__=="__main__":
register()
"""
old version
import bpy
bl_info = {
"name": "Display Local Nodes",
"description": "Adds a display in your Node Editor, to show local nodes, in the Tool section.",
"author": "Ronboprime",
"email":"ronboprime@gmail.com",
"version": (1, 5),
"blender": (4,0,0),
"location": "Node Editor> Navigation Bar> Tool",
"warning": "",
"doc_url": "",
"tracker_url": "",
"category": "Node",
}
# Get all node groups
#node_tree = bpy.context.space_data.node_tree
class NODE_OT_add_node_group(bpy.types.Operator):
bl_idname = "node_ot.add_node_group"
bl_label = "Add Node Group"
# Property to hold the name of the node group to add
node_group_name: bpy.props.StringProperty()
def execute(self, context):
#sanity check
obj=bpy.context.active_object
print(obj)
#is this thing on?
if obj==None:
self.report({'WARNING'},"how can you have any node tree, if you don't have your active object!")
return{"CANCELLED"}
# Get the node groups
node_groups = bpy.data.node_groups
# Get the active node tree
node_tree = context.space_data.node_tree
# what if there's no node tree?
try:
# Create a new group node
new_node = node_tree.nodes.new(type='GeometryNodeGroup')
# Set the node group of the new node
new_node.node_tree = bpy.data.node_groups[self.node_group_name]
# Position the new node
new_node.location = (420, 420)
# Handled.
except AttributeError:
self.report({'WARNING'}, "No active node tree found... Good heavens, fix your life man!")
return {'CANCELLED'}
# If can do, do!
return {'FINISHED'}
class NODE_PT_my_panel(bpy.types.Panel):
bl_idname="NODE_PT_panel"
bl_label = "Local Node Groups"
bl_space_type = 'NODE_EDITOR'
bl_region_type = 'UI'
bl_category = "Tool"
def draw(self, context):
# Get the node groups
node_groups=bpy.data.node_groups
# Initialize the UI
col = self.layout.column(align=True)
# Iterate over node groups
for ng in bpy.data.node_groups:
# Create a button for the node group
op = col.operator("node_ot.add_node_group", text=ng.name,icon="KEYTYPE_JITTER_VEC")
# Set the operator's node_group_name property
op.node_group_name = ng.name
#Registration
classes=[NODE_PT_my_panel, NODE_OT_add_node_group]
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__=="__main__":
register()
"""