-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholitools.py
190 lines (160 loc) · 5.92 KB
/
olitools.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
# ------------------------------------
# Custom Mode Setter
# ------------------------------------
# Ver 0.1:
# - Joining mode setter and delete
# ------------------------------------
import bpy
bl_info={
"name" : "Oli Tools",
"author": "Oliver Reischl <[email protected]>",
"version": (0, 1),
"description" : "Various little operators to ",
"blender": (3, 5, 0),
"location": "",
"warning": "",
"wiki_url": "http://manuals.clawjelly.net/Blender/PersonalAddons",
"category": "Generic"
}
class OLI_OP_custom_mode_setter(bpy.types.Operator):
"""A custom submode setter, helps make blender behave like i want to"""
bl_idname = "olitools.custom_mode_setter"
bl_label = "Custom Mode Setter"
mode: bpy.props.IntProperty(
name = 'Mode Number',
default = 4
)
def custom_mode_setter(self, context, mode):
obj = context.active_object
# Is object a linked object?
if obj.library != None:
bpy.context.window_manager.popup_menu(
lambda self, ctx: (self.layout.label(text="Can't edit linked objects.")) ,
title="Warning",
icon='ERROR')
return
# armatures
if obj.type=='ARMATURE':
print("Armature!")
if mode==1:
bpy.ops.object.mode_set(mode="EDIT")
elif mode==2:
bpy.ops.object.mode_set(mode="POSE")
elif mode==4:
bpy.ops.object.mode_set(mode="OBJECT")
return
# mesh sub object modes
elif obj.type=='MESH':
# In UV mode?
if context.area.type=="IMAGE_EDITOR" and bpy.context.scene.tool_settings.use_uv_select_sync == False:
if mode==1:
bpy.ops.uv.select_mode(type='VERTEX')
if mode==2:
bpy.ops.uv.select_mode(type='EDGE')
if mode==3:
bpy.ops.uv.select_mode(type='FACE')
return
### still in
if mode==1:
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.select_mode(type="VERT")
elif mode==2:
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.select_mode(type="EDGE")
elif mode==3:
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.select_mode(type="FACE")
elif mode==4:
bpy.ops.object.mode_set(mode="OBJECT")
return
# default behaviour
else:
if mode==1:
try:
bpy.ops.object.mode_set(mode="EDIT")
except Exception as e:
pass
else:
bpy.ops.object.mode_set(mode="OBJECT")
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
self.custom_mode_setter(context, self.mode)
return {'FINISHED'}
class OLI_OT_delete_context(bpy.types.Operator):
"""A custom delete operator, mimicking the delete function in 3dsmax"""
bl_idname = "olitools.delete_context"
bl_label = "Delete/dissolve without dialog"
@classmethod
def poll(cls, context):
isCorrect= context.active_object is not None
return isCorrect
def execute(self, context):
if context.mode=="EDIT_MESH":
vertex, edge, face = context.scene.tool_settings.mesh_select_mode
if vertex:
bpy.ops.mesh.dissolve_verts()
if edge:
bpy.ops.mesh.dissolve_edges()
if face:
bpy.ops.mesh.delete(type='FACE')
return {'FINISHED'}
bpy.ops.object.delete()
return {'FINISHED'}
class OLI_OT_select_full_hierarchy(bpy.types.Operator):
"""Selects the full hierarchy to the last child."""
bl_idname = "olitools.select_full_hierarchy"
bl_label = "Select full hierarchy"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
selected_objects = context.selected_objects
obj_act = context.object
if context.object not in selected_objects:
selected_objects.append(context.object)
while len(selected_objects)>0:
obj = selected_objects.pop()
selected_objects.extend([child for child in obj.children])
obj.select_set(True)
return {'FINISHED'}
class OLI_OT_increase_gizmo_size(bpy.types.Operator):
"""Increases the base size of all gimzos on the viewport"""
bl_idname = "olitools.increase_gizmo_size"
bl_label = "Increase Gizmo Size"
def execute(self, context):
sizes = [10, 20, 30, 50, 70, 100, 140, 200]
current_size = context.preferences.view.gizmo_size
for size in sizes:
if size > current_size:
context.preferences.view.gizmo_size = size
break
return {'FINISHED'}
class OLI_OT_decrease_gizmo_size(bpy.types.Operator):
"""Increases the base size of all gimzos on the viewport"""
bl_idname = "olitools.decrease_gizmo_size"
bl_label = "Decrease Gizmo Size"
def execute(self, context):
sizes = [200, 140, 100, 70, 50, 30, 20, 10]
current_size = context.preferences.view.gizmo_size
for size in sizes:
if size < current_size:
context.preferences.view.gizmo_size = size
break
return {'FINISHED'}
blender_classes=[
OLI_OP_custom_mode_setter,
OLI_OT_delete_context,
OLI_OT_select_full_hierarchy,
OLI_OT_increase_gizmo_size,
OLI_OT_decrease_gizmo_size
]
def register():
for blender_class in blender_classes:
bpy.utils.register_class(blender_class)
def unregister():
for blender_class in reversed(blender_classes):
bpy.utils.unregister_class(blender_class)
if __name__ == "__main__":
register()