forked from bookyakuno/Blender-Scramble-Addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVIEW3D_MT_object.py
235 lines (203 loc) · 9.43 KB
/
VIEW3D_MT_object.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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# 「3Dビュー」エリア > 「オブジェクト」モード > 「オブジェクト」メニュー
# "3D View" Area > "Object" Mode > "Object" Menu
import bpy, bmesh
from bpy.props import *
################
# パイメニュー #
################
class CopyPieOperator(bpy.types.Operator):
bl_idname = "object.copy_pie_operator"
bl_label = "Pie menu : Copy to Other Objects"
bl_description = "Copy active object's specific property to selected objects"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
bpy.ops.wm.call_menu_pie(name=CopyPie.bl_idname)
return {'FINISHED'}
class CopyPie(bpy.types.Menu):
bl_idname = "VIEW3D_MT_object_pie_copy"
bl_label = "Pie menu : Copy to Other Objects"
bl_description = "Copy active object's specific property to selected objects"
def draw(self, context):
#Left - Right - Bottom - Top - TopLeft - TopRight - BottomLeft - BottomRight
pie_menu = self.layout.menu_pie()
pie_menu.operator('object.copy_object_name', icon="COPYDOWN")#OBJECT_PT_context_object で定義
pie_menu.operator('object.make_link_object_name', icon="SYNTAX_OFF")#VIEW3D_MT_make_links.py で定義
op = pie_menu.operator('object.make_link_transform', icon='CON_LOCLIKE', text="Copy Location")#VIEW3D_MT_make_links.py で定義
op.copy_location, op.copy_rotation, op.copy_scale = True, False, False
pie_menu.operator('object.make_links_data', icon='MATERIAL', text="Copy Material").type = 'MATERIAL'
pie_menu.operator('object.make_links_data', icon='MODIFIER', text="Copy Modifier").type = 'MODIFIERS'
pie_menu.operator('object.make_links_data', icon='GROUP', text="Move to Same Collection").type = 'GROUPS'
op = pie_menu.operator('object.make_link_transform', icon='CON_ROTLIKE', text="Copy Rotation")
op.copy_location, op.copy_rotation, op.copy_scale = False, True, False
op = pie_menu.operator('object.make_link_transform', icon='CON_SIZELIKE', text="Copy Scale")
op.copy_location, op.copy_rotation, op.copy_scale = False, False, True
class ObjectModePieOperator(bpy.types.Operator):
bl_idname = "object.object_mode_pie_operator"
bl_label = "Pie menu : Object's Mode"
bl_description = "Switch object interaction mode"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
bpy.ops.wm.call_menu_pie(name=ObjectModePie.bl_idname)
return {'FINISHED'}
class ObjectModePie(bpy.types.Menu):
bl_idname = "VIEW3D_MT_object_pie_object_mode"
bl_label = "Pie menu : Object's Mode"
bl_description = "Switch object interaction mode"
def draw(self, context):
#Left - Right - Bottom - Top - TopLeft - TopRight - BottomLeft - BottomRight
pie_menu = self.layout.menu_pie()
pie_menu.enabled = (not context.active_object == None)
pie_menu.operator(SetObjectMode.bl_idname, text="Pose", icon="POSE_HLT").mode = "POSE"
pie_menu.operator(SetObjectMode.bl_idname, text="Sculpt", icon="SCULPTMODE_HLT").mode = "SCULPT"
pie_menu.operator(SetObjectMode.bl_idname, text="Weight Paint", icon="WPAINT_HLT").mode = "WEIGHT_PAINT"
pie_menu.operator(SetObjectMode.bl_idname, text="Object Mode", icon="OBJECT_DATAMODE").mode = "OBJECT"
pie_menu.operator(SetObjectMode.bl_idname, text="Particle Edit", icon="PARTICLEMODE").mode = "PARTICLE_EDIT"
pie_menu.operator(SetObjectMode.bl_idname, text="Edit Mode", icon="EDITMODE_HLT").mode = "EDIT"
pie_menu.operator(SetObjectMode.bl_idname, text="Texture Paint", icon="TPAINT_HLT").mode = "TEXTURE_PAINT"
pie_menu.operator(SetObjectMode.bl_idname, text="Vertex Paint", icon="VPAINT_HLT").mode = "VERTEX_PAINT"
class SetObjectMode(bpy.types.Operator): #
bl_idname = "object.set_object_mode"
bl_label = "Switch Object's Mode"
bl_description = "Switch object interaction mode"
bl_options = {'REGISTER'}
mode : StringProperty(name="Interaction Mode", default="OBJECT")
def execute(self, context):
try:
bpy.ops.object.mode_set(mode=self.mode)
except TypeError:
self.report(type={"ERROR"}, message="The selected mode cannot use for active object")
return {'CANCELLED'}
return {'FINISHED'}
class SubdivisionSetPieOperator(bpy.types.Operator):
bl_idname = "object.subdivision_set_pie_operator"
bl_label = "Pie menu : Subsurf"
bl_description = "Change properties of selected objects' subdivision surface modifiers"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
bpy.ops.wm.call_menu_pie(name=SubdivisionSetPie.bl_idname)
return {'FINISHED'}
class SubdivisionSetPie(bpy.types.Menu):
bl_idname = "VIEW3D_MT_object_pie_subdivision_set"
bl_label = "Pie menu : Subsurface"
bl_description = "Change properties of selected objects' subdivision surface modifiers"
def draw(self, context):
#Left - Right - Bottom - Top - TopLeft - TopRight - BottomLeft - BottomRight
pie_menu = self.layout.menu_pie()
#以下の関数は全て DATA_PT_modifiers で定義
pie_menu.menu_pie().operator('object.add_subsurf', icon="MODIFIER")
box = pie_menu.menu_pie().box().box().box()
box.enabled = bpy.ops.object.set_viewport_subsurf_level.poll()
box.operator_context = 'EXEC_DEFAULT'
box.label(text="Set Number of Subdivisions in Viewport", icon="VIEW3D")
row = box.row(align=True)
for i in range(5):
row.operator('object.set_viewport_subsurf_level', text=str(i+1)).level_enum = str(i+1)
pie_menu.menu_pie().operator('object.set_subsurf_optimal_display', icon="MOD_WIREFRAME")
pie_menu.menu_pie().operator('object.equalize_subsurf_level', icon="LIBRARY_DATA_DIRECT")
pie_menu.menu_pie().operator('object.delete_subsurf', icon="CANCEL")
box = pie_menu.menu_pie().box().box().box()
box.enabled = bpy.ops.object.set_render_subsurf_level.poll()
box.operator_context = 'EXEC_DEFAULT'
box.label(text="Set Number of Subdivisions When Rendering", icon="RESTRICT_RENDER_OFF")
row = box.row(align=True)
for i in range(5):
row.operator('object.set_render_subsurf_level', text=str(i+1)).level_enum= str(i+1)
class DrawTypePieOperator(bpy.types.Operator):
bl_idname = "object.display_type_pie_operator"
bl_label = "Pie menu : Display in Viewport"
bl_description = "Change display method of selected objects"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
bpy.ops.wm.call_menu_pie(name=DrawTypePie.bl_idname)
return {'FINISHED'}
class DrawTypePie(bpy.types.Menu):
bl_idname = "VIEW3D_MT_object_pie_display_type"
bl_label = "Pie menu : Display in Viewport"
bl_description = "Change display method of selected objects"
def draw(self, context):
layout = self.layout.menu_pie()
layout.enabled = (not context.active_object == None)
ps = ['BOUNDS', 'WIRE', 'SOLID', 'TEXTURED']
icons = ["SHADING_BBOX", "SHADING_WIRE", "SHADING_SOLID", "SHADING_TEXTURE"]
act_obj = context.active_object
for p, icon in zip(ps, icons):
name = bpy.types.UILayout.enum_item_name(act_obj, 'display_type', p)
layout.operator(SetDrawType.bl_idname, text=name, icon=icon).type = p
class SetDrawType(bpy.types.Operator): #
bl_idname = "object.set_display_type"
bl_label = "Change Display Method"
bl_description = "Change display method of selected objects"
bl_options = {'REGISTER'}
type : StringProperty(name="Display As", default="OBJECT")
def execute(self, context):
for obj in context.selected_objects:
obj.display_type = self.type
return {'FINISHED'}
################
# オペレーター #
################
class DeleteUnmassage(bpy.types.Operator):
bl_idname = "object.delete_unmassage"
bl_label = "Delete Objects (without confirming)"
bl_description = "Deletes all selected objects without displaying the confirmation message"
bl_options = {'REGISTER', 'UNDO'}
use_global : BoolProperty(name="Delete All", default=False)
def execute(self, context):
bpy.ops.object.delete(use_global=self.use_global)
return {'FINISHED'}
################
# サブメニュー #
################
class ShortcutMenu(bpy.types.Menu):
bl_idname = "VIEW3D_MT_object_shortcut"
bl_label = "Change Properties (For Shortcut)"
bl_description = "Functions to change objects' properties that can be used easily by assigning shortcut"
def draw(self, context):
self.layout.operator(DeleteUnmassage.bl_idname, icon="PLUGIN")
self.layout.operator('object.apply_modifiers_and_join', icon="PLUGIN")#DATA_PT_modifiers で定義
self.layout.separator()
self.layout.operator(CopyPieOperator.bl_idname, icon="PLUGIN")
self.layout.operator(ObjectModePieOperator.bl_idname, icon="PLUGIN")
self.layout.operator(SubdivisionSetPieOperator.bl_idname, icon="PLUGIN")
self.layout.operator(DrawTypePieOperator.bl_idname, icon="PLUGIN")
################
# クラスの登録 #
################
classes = [
CopyPieOperator,
CopyPie,
ObjectModePieOperator,
ObjectModePie,
SetObjectMode,
SubdivisionSetPieOperator,
SubdivisionSetPie,
DrawTypePieOperator,
DrawTypePie,
SetDrawType,
DeleteUnmassage,
ShortcutMenu
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
################
# メニュー追加 #
################
# メニューのオン/オフの判定
def IsMenuEnable(self_id):
for id in bpy.context.preferences.addons[__name__.partition('.')[0]].preferences.disabled_menu.split(','):
if (id == self_id):
return False
else:
return True
# メニューを登録する関数
def menu(self, context):
if (IsMenuEnable(__name__.split('.')[-1])):
self.layout.separator()
self.layout.menu(ShortcutMenu.bl_idname, icon="PLUGIN")
if (context.preferences.addons[__name__.partition('.')[0]].preferences.use_disabled_menu):
self.layout.separator()
self.layout.operator('wm.toggle_menu_enable', icon='CANCEL').id = __name__.split('.')[-1]