1 # SPDX-License-Identifier: GPL-2.0-or-later
4 "name": "Hotkey: 'Ctrl Tab'",
5 "description": "Switch between 3d view object/edit modes",
6 "author": "pitiwazou, meta-androcto, italic",
12 "category": "Mode Switch Pie"
16 from bpy
.types
import (
22 class PIE_OT_ClassObject(Operator
):
23 bl_idname
= "class.object"
24 bl_label
= "Class Object"
25 bl_description
= "Edit/Object Mode Switch"
26 bl_options
= {'REGISTER', 'UNDO'}
28 def execute(self
, context
):
29 if context
.object.mode
== "OBJECT":
30 bpy
.ops
.object.mode_set(mode
="EDIT")
32 bpy
.ops
.object.mode_set(mode
="OBJECT")
36 class PIE_OT_ClassTexturePaint(Operator
):
37 bl_idname
= "class.pietexturepaint"
38 bl_label
= "Class Texture Paint"
39 bl_description
= "Texture Paint"
40 bl_options
= {'REGISTER', 'UNDO'}
42 def execute(self
, context
):
43 if context
.object.mode
== "EDIT":
44 bpy
.ops
.object.mode_set(mode
="OBJECT")
45 bpy
.ops
.paint
.texture_paint_toggle()
47 bpy
.ops
.paint
.texture_paint_toggle()
51 class PIE_OT_ClassWeightPaint(Operator
):
52 bl_idname
= "class.pieweightpaint"
53 bl_label
= "Class Weight Paint"
54 bl_description
= "Weight Paint"
55 bl_options
= {'REGISTER', 'UNDO'}
57 def execute(self
, context
):
58 if context
.object.mode
== "EDIT":
59 bpy
.ops
.object.mode_set(mode
="OBJECT")
60 bpy
.ops
.paint
.weight_paint_toggle()
62 bpy
.ops
.paint
.weight_paint_toggle()
66 class PIE_OT_ClassVertexPaint(Operator
):
67 bl_idname
= "class.pievertexpaint"
68 bl_label
= "Class Vertex Paint"
69 bl_description
= "Vertex Paint"
70 bl_options
= {'REGISTER', 'UNDO'}
72 def execute(self
, context
):
73 if context
.object.mode
== "EDIT":
74 bpy
.ops
.object.mode_set(mode
="OBJECT")
75 bpy
.ops
.paint
.vertex_paint_toggle()
77 bpy
.ops
.paint
.vertex_paint_toggle()
81 class PIE_OT_ClassParticleEdit(Operator
):
82 bl_idname
= "class.pieparticleedit"
83 bl_label
= "Class Particle Edit"
84 bl_description
= "Particle Edit (must have active particle system)"
85 bl_options
= {'REGISTER', 'UNDO'}
87 def execute(self
, context
):
88 if context
.object.mode
== "EDIT":
89 bpy
.ops
.object.mode_set(mode
="OBJECT")
90 bpy
.ops
.particle
.particle_edit_toggle()
92 bpy
.ops
.particle
.particle_edit_toggle()
97 class PIE_OT_SetObjectModePie(Operator
):
98 bl_idname
= "object.set_object_mode_pie"
99 bl_label
= "Set the object interactive mode"
100 bl_description
= "I set the interactive mode of object"
101 bl_options
= {'REGISTER'}
103 mode
: bpy
.props
.StringProperty(name
="Interactive mode", default
="OBJECT")
105 def execute(self
, context
):
106 if (context
.active_object
):
108 bpy
.ops
.object.mode_set(mode
=self
.mode
)
110 msg
= context
.active_object
.name
+ " It is not possible to enter into the interactive mode"
111 self
.report(type={"WARNING"}, message
=msg
)
113 self
.report(type={"WARNING"}, message
="There is no active object")
117 # Edit Selection Modes
118 class PIE_OT_ClassVertex(Operator
):
119 bl_idname
= "class.vertex"
120 bl_label
= "Class Vertex"
121 bl_description
= "Vert Select Mode"
122 bl_options
= {'REGISTER', 'UNDO'}
124 def execute(self
, context
):
125 if context
.object.mode
!= "EDIT":
126 bpy
.ops
.object.mode_set(mode
="EDIT")
127 bpy
.ops
.mesh
.select_mode(use_extend
=False, use_expand
=False, type='VERT')
128 if bpy
.ops
.mesh
.select_mode
!= "EDGE, FACE":
129 bpy
.ops
.mesh
.select_mode(use_extend
=False, use_expand
=False, type='VERT')
133 class PIE_OT_ClassEdge(Operator
):
134 bl_idname
= "class.edge"
135 bl_label
= "Class Edge"
136 bl_description
= "Edge Select Mode"
137 bl_options
= {'REGISTER', 'UNDO'}
139 def execute(self
, context
):
140 if context
.object.mode
!= "EDIT":
141 bpy
.ops
.object.mode_set(mode
="EDIT")
142 bpy
.ops
.mesh
.select_mode(use_extend
=False, use_expand
=False, type='EDGE')
143 if bpy
.ops
.mesh
.select_mode
!= "VERT, FACE":
144 bpy
.ops
.mesh
.select_mode(use_extend
=False, use_expand
=False, type='EDGE')
148 class PIE_OT_ClassFace(Operator
):
149 bl_idname
= "class.face"
150 bl_label
= "Class Face"
151 bl_description
= "Face Select Mode"
152 bl_options
= {'REGISTER', 'UNDO'}
154 def execute(self
, context
):
155 if context
.object.mode
!= "EDIT":
156 bpy
.ops
.object.mode_set(mode
="EDIT")
157 bpy
.ops
.mesh
.select_mode(use_extend
=False, use_expand
=False, type='FACE')
158 if bpy
.ops
.mesh
.select_mode
!= "VERT, EDGE":
159 bpy
.ops
.mesh
.select_mode(use_extend
=False, use_expand
=False, type='FACE')
163 class PIE_OT_VertsEdgesFaces(Operator
):
164 bl_idname
= "verts.edgesfaces"
165 bl_label
= "Verts Edges Faces"
166 bl_description
= "Vert/Edge/Face Select Mode"
167 bl_options
= {'REGISTER', 'UNDO'}
169 def execute(self
, context
):
170 if context
.object.mode
!= "EDIT":
171 bpy
.ops
.object.mode_set(mode
="EDIT")
172 bpy
.ops
.mesh
.select_mode(use_extend
=False, use_expand
=False, type='VERT')
173 if bpy
.ops
.mesh
.select_mode
!= "VERT, EDGE, FACE":
174 bpy
.ops
.object.mode_set(mode
="EDIT")
175 bpy
.ops
.mesh
.select_mode(use_extend
=False, use_expand
=False, type='VERT')
176 bpy
.ops
.mesh
.select_mode(use_extend
=True, use_expand
=False, type='EDGE')
177 bpy
.ops
.mesh
.select_mode(use_extend
=True, use_expand
=False, type='FACE')
182 class PIE_MT_ObjectEditotherModes(Menu
):
183 """Edit/Object Others modes"""
184 bl_idname
= "MENU_MT_objecteditmodeothermodes"
185 bl_label
= "Edit Selection Modes"
187 def draw(self
, context
):
189 pie
= layout
.menu_pie()
190 box
= pie
.split().column()
192 box
.operator("class.vertex", text
="Vertex", icon
='VERTEXSEL')
193 box
.operator("class.edge", text
="Edge", icon
='EDGESEL')
194 box
.operator("class.face", text
="Face", icon
='FACESEL')
195 box
.operator("verts.edgesfaces", text
="Vertex/Edges/Faces", icon
='OBJECT_DATAMODE')
198 class PIE_MT_ObjectEditMode(Menu
):
200 bl_idname
= "PIE_MT_objecteditmode"
201 bl_label
= "Mode Switch (Ctrl Tab)"
203 def draw(self
, context
):
206 # No Object Selected #
207 if not ob
or not ob
.select_get():
208 message
= "No Active Object Selected"
209 pie
= layout
.menu_pie()
214 box
.label(text
=message
, icon
="INFO")
216 elif ob
and ob
.type == 'MESH' and ob
.mode
in {
217 'OBJECT', 'SCULPT', 'VERTEX_PAINT',
218 'WEIGHT_PAINT', 'TEXTURE_PAINT',
219 'PARTICLE_EDIT', 'GPENCIL_EDIT',
221 pie
= layout
.menu_pie()
223 pie
.operator("class.pieweightpaint", text
="Weight Paint", icon
='WPAINT_HLT')
225 pie
.operator("class.pietexturepaint", text
="Texture Paint", icon
='TPAINT_HLT')
227 pie
.menu("MENU_MT_objecteditmodeothermodes", text
="Edit Modes", icon
='EDITMODE_HLT')
229 pie
.operator("class.object", text
="Object/Edit Toggle", icon
='OBJECT_DATAMODE')
231 pie
.operator("sculpt.sculptmode_toggle", text
="Sculpt", icon
='SCULPTMODE_HLT')
233 pie
.operator("class.pievertexpaint", text
="Vertex Paint", icon
='VPAINT_HLT')
237 if context
.object.particle_systems
:
238 pie
.operator("class.pieparticleedit", text
="Particle Edit", icon
='PARTICLEMODE')
242 elif ob
and ob
.type == 'MESH' and ob
.mode
in {'EDIT'}:
243 pie
= layout
.menu_pie()
245 pie
.operator("class.pieweightpaint", text
="Weight Paint", icon
='WPAINT_HLT')
247 pie
.operator("class.pietexturepaint", text
="Texture Paint", icon
='TPAINT_HLT')
249 pie
.menu("MENU_MT_objecteditmodeothermodes", text
="Edit Modes", icon
='EDITMODE_HLT')
251 pie
.operator("class.object", text
="Edit/Object Toggle", icon
='OBJECT_DATAMODE')
253 pie
.operator("sculpt.sculptmode_toggle", text
="Sculpt", icon
='SCULPTMODE_HLT')
255 pie
.operator("class.pievertexpaint", text
="Vertex Paint", icon
='VPAINT_HLT')
259 if context
.object.particle_systems
:
260 pie
.operator("class.pieparticleedit", text
="Particle Edit", icon
='PARTICLEMODE')
264 elif ob
and ob
.type == 'CURVE':
265 pie
= layout
.menu_pie()
273 pie
.operator("object.editmode_toggle", text
="Edit/Object", icon
='OBJECT_DATAMODE')
283 elif ob
and ob
.type == 'ARMATURE':
284 pie
= layout
.menu_pie()
286 pie
.operator(PIE_OT_SetObjectModePie
.bl_idname
, text
="Object", icon
="OBJECT_DATAMODE").mode
= "OBJECT"
288 pie
.operator(PIE_OT_SetObjectModePie
.bl_idname
, text
="Pose", icon
="POSE_HLT").mode
= "POSE"
290 pie
.operator(PIE_OT_SetObjectModePie
.bl_idname
, text
="Edit", icon
="EDITMODE_HLT").mode
= "EDIT"
292 pie
.operator("object.editmode_toggle", text
="Edit Mode", icon
='OBJECT_DATAMODE')
302 elif ob
and ob
.type == 'FONT':
303 pie
= layout
.menu_pie()
307 pie
.operator("object.editmode_toggle", text
="Edit/Object Toggle", icon
='OBJECT_DATAMODE')
314 elif ob
and ob
.type == 'SURFACE':
315 pie
= layout
.menu_pie()
319 pie
.operator("object.editmode_toggle", text
="Edit/Object Toggle", icon
='OBJECT_DATAMODE')
326 elif ob
and ob
.type == 'META':
327 pie
= layout
.menu_pie()
331 pie
.operator("object.editmode_toggle", text
="Edit/Object Toggle", icon
='OBJECT_DATAMODE')
338 elif ob
and ob
.type == 'LATTICE':
339 pie
= layout
.menu_pie()
343 pie
.operator("object.editmode_toggle", text
="Edit/Object Toggle", icon
='OBJECT_DATAMODE')
348 if ob
and ob
.type == 'GPENCIL':
349 pie
= layout
.menu_pie()
351 pie
.operator(PIE_OT_SetObjectModePie
.bl_idname
, text
="Sculpt",
352 icon
="SCULPTMODE_HLT").mode
= "SCULPT_GPENCIL"
354 pie
.operator(PIE_OT_SetObjectModePie
.bl_idname
, text
="Draw", icon
="GREASEPENCIL").mode
= "PAINT_GPENCIL"
356 pie
.operator(PIE_OT_SetObjectModePie
.bl_idname
, text
="Edit", icon
="EDITMODE_HLT").mode
= "EDIT_GPENCIL"
358 pie
.operator(PIE_OT_SetObjectModePie
.bl_idname
, text
="Object", icon
="OBJECT_DATAMODE").mode
= "OBJECT"
367 PIE_OT_SetObjectModePie
.bl_idname
,
369 icon
="WPAINT_HLT").mode
= "WEIGHT_GPENCIL"
371 elif ob
and ob
.type in {"LIGHT", "CAMERA", "EMPTY", "SPEAKER"}:
372 message
= "Active Object has only Object Mode available"
373 pie
= layout
.menu_pie()
378 box
.label(text
=message
, icon
="INFO")
382 PIE_MT_ObjectEditMode
,
387 PIE_MT_ObjectEditotherModes
,
388 PIE_OT_ClassTexturePaint
,
389 PIE_OT_ClassWeightPaint
,
390 PIE_OT_ClassVertexPaint
,
391 PIE_OT_ClassParticleEdit
,
392 PIE_OT_VertsEdgesFaces
,
393 PIE_OT_SetObjectModePie
,
401 bpy
.utils
.register_class(cls
)
403 wm
= bpy
.context
.window_manager
404 if wm
.keyconfigs
.addon
:
406 km
= wm
.keyconfigs
.addon
.keymaps
.new(name
='Object Non-modal')
407 kmi
= km
.keymap_items
.new('wm.call_menu_pie', 'TAB', 'PRESS', ctrl
=True)
408 kmi
.properties
.name
= "PIE_MT_objecteditmode"
409 addon_keymaps
.append((km
, kmi
))
411 km
= wm
.keyconfigs
.addon
.keymaps
.new(name
='Grease Pencil Stroke Edit Mode')
412 kmi
= km
.keymap_items
.new('wm.call_menu_pie', 'TAB', 'PRESS', ctrl
=True)
413 kmi
.properties
.name
= "PIE_MT_objecteditmode"
414 addon_keymaps
.append((km
, kmi
))
419 bpy
.utils
.unregister_class(cls
)
421 wm
= bpy
.context
.window_manager
422 kc
= wm
.keyconfigs
.addon
424 for km
, kmi
in addon_keymaps
:
425 km
.keymap_items
.remove(kmi
)
426 addon_keymaps
.clear()
429 if __name__
== "__main__":