forked from BrendanParmer/NodeToPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
58 lines (45 loc) · 1.76 KB
/
Copy pathui.py
File metadata and controls
58 lines (45 loc) · 1.76 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
import bpy
from bpy.types import Panel
from bpy.types import Menu
from .operator import NTPGeoNodesOperator
class NTPGeoNodesPanel(Panel):
bl_label = "Geometry Nodes to Python"
bl_idname = "NODE_PT_geo_nodes"
bl_space_type = 'NODE_EDITOR'
bl_region_type = 'UI'
bl_context = ''
bl_category = "NodeToPython"
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@classmethod
def poll(cls, context):
return True
def draw_header(self, context):
layout = self.layout
def draw(self, context):
layout = self.layout
col = layout.column()
row = col.row()
# Disables menu when len of geometry nodes is 0
geo_node_groups = [node_tree for node_tree in bpy.data.node_groups
if node_tree.bl_idname == 'GeometryNodeTree']
geo_node_groups_exist = len(geo_node_groups) > 0
row.enabled = geo_node_groups_exist
row.alignment = 'EXPAND'
row.operator_context = 'INVOKE_DEFAULT'
row.menu("NODE_MT_ntp_geo_nodes", text="Geometry Nodes")
class NTPGeoNodesMenu(Menu):
bl_idname = "NODE_MT_ntp_geo_nodes"
bl_label = "Select Geo Nodes"
@classmethod
def poll(cls, context):
return True
def draw(self, context):
layout = self.layout.column_flow(columns=1)
layout.operator_context = 'INVOKE_DEFAULT'
geo_node_groups = [node_tree for node_tree in bpy.data.node_groups
if node_tree.bl_idname == 'GeometryNodeTree']
for node_tree in geo_node_groups:
op = layout.operator(NTPGeoNodesOperator.bl_idname,
text=node_tree.name)
op.geo_nodes_group_name = node_tree.name