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
49 lines (40 loc) · 1.41 KB
/
Copy pathui.py
File metadata and controls
49 lines (40 loc) · 1.41 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
import bpy
from bpy.types import Panel
from bpy.types import Menu
from .operator import NTPShaderOperator
class NTPShaderPanel(Panel):
bl_label = "Material to Python"
bl_idname = "NODE_PT_mat_to_python"
bl_space_type = 'NODE_EDITOR'
bl_region_type = 'UI'
bl_context = ''
bl_category = "NodeToPython"
@classmethod
def poll(cls, context):
return True
def draw_header(self, context):
layout = self.layout
def draw(self, context):
layout = self.layout
row = layout.row()
# Disables menu when there are no materials
materials = [mat for mat in bpy.data.materials if mat.node_tree]
materials_exist = len(materials) > 0
row.enabled = materials_exist
row.alignment = 'EXPAND'
row.operator_context = 'INVOKE_DEFAULT'
row.menu("NODE_MT_ntp_material", text="Materials")
class NTPShaderMenu(Menu):
bl_idname = "NODE_MT_ntp_material"
bl_label = "Select Material"
@classmethod
def poll(cls, context):
return True
def draw(self, context):
layout = self.layout.column_flow(columns=1)
layout.operator_context = 'INVOKE_DEFAULT'
for mat in bpy.data.materials:
if mat.node_tree:
op = layout.operator(NTPShaderOperator.bl_idname,
text=mat.name)
op.material_name = mat.name