-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathblender2.83_good_UI_example_2.py
163 lines (107 loc) · 4.27 KB
/
blender2.83_good_UI_example_2.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
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
bl_info = {
"name": "Object Adder",
"author": "Darkfall",
"version": (1, 1),
"blender": (2, 80, 0),
"location": "View3D > Toolbar > Object Adder",
"description": "Adds objects and other functions",
"warning": "",
"wiki_url": "",
"category": "Add Mesh",
}
import bpy
#This is the Main Panel (Parent of Panel A and B)
class MainPanel(bpy.types.Panel):
bl_label = "Object Adder"
bl_idname = "VIEW_PT_MainPanel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Object Adder'
def draw(self, context):
layout = self.layout
layout.scale_y = 1.2
row = layout.row()
row.label(text= "Add an object", icon= 'OBJECT_ORIGIN')
row = layout.row()
row.operator("wm.myop", icon= 'CUBE', text= "Cube")
row.operator("mesh.primitive_uv_sphere_add", icon= 'SPHERE', text= "Sphere")
row.operator("mesh.primitive_monkey_add", icon= 'MESH_MONKEY', text= "Suzanne")
row = layout.row()
row.operator("curve.primitive_bezier_curve_add", icon= 'CURVE_BEZCURVE', text= "Bezier Curve")
row.operator("curve.primitive_bezier_circle_add", icon= 'CURVE_BEZCIRCLE', text= "Bezier Circle")
row = layout.row()
row.operator("object.text_add", icon= 'FILE_FONT', text= "Add Font")
row = layout.row()
#This is Panel A - The Scale Sub Panel (Child of MainPanel)
class PanelA(bpy.types.Panel):
bl_label = "Scale"
bl_idname = "VIEW_PT_PanelA"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Object Adder'
bl_parent_id = 'VIEW_PT_MainPanel'
bl_options = {'DEFAULT_CLOSED'}
def draw(self, context):
layout = self.layout
obj = context.object
row = layout.row()
row.label(text= "Select an option to scale your", icon= 'FONT_DATA')
row = layout.row()
row.label(text= " object.")
row = layout.row()
row.operator("transform.resize")
row = layout.row()
layout.scale_y = 1.2
col = layout.column()
col.prop(obj, "scale")
#This is Panel B - The Specials Sub Panel (Child of MainPanel)
class PanelB(bpy.types.Panel):
bl_label = "Specials"
bl_idname = "VIEW_PT_PanelB"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Object Adder'
bl_parent_id = 'VIEW_PT_MainPanel'
bl_options = {'DEFAULT_CLOSED'}
def draw(self, context):
layout = self.layout
row = layout.row()
row.label(text= "Select a Special Option", icon= 'COLOR_BLUE')
row = layout.row()
row.operator("object.shade_smooth", icon= 'MOD_SMOOTH', text= "Set Smooth Shading")
row.operator("object.subdivision_set", icon= 'MOD_SUBSURF', text= "Add Subsurf")
row = layout.row()
row.operator("object.modifier_add", icon= 'MODIFIER')
class WM_OT_myOp(bpy.types.Operator):
"""Open the Add Cube Dialog box"""
bl_label = "Add Cube Dialog Box"
bl_idname = "wm.myop"
text = bpy.props.StringProperty(name= "Enter Name", default= "")
scale = bpy.props.FloatVectorProperty(name= "Scale:", default= (1,1,1))
def execute(self, context):
t = self.text
s = self.scale
bpy.ops.mesh.primitive_cube_add()
obj = bpy.context.object
obj.name = t
obj.scale[0] = s[0]
obj.scale[1] = s[1]
obj.scale[2] = s[2]
return {'FINISHED'}
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
#Here we are Registering the Classes
def register():
bpy.utils.register_class(MainPanel)
bpy.utils.register_class(PanelA)
bpy.utils.register_class(PanelB)
bpy.utils.register_class(WM_OT_myOp)
#Here we are UnRegistering the Classes
def unregister():
bpy.utils.unregister_class(MainPanel)
bpy.utils.unregister_class(PanelA)
bpy.utils.unregister_class(PanelB)
bpy.utils.unregister_class(WM_OT_myOp)
#This is required in order for the script to run in the text editor
if __name__ == "__main__":
register()