-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc_ot.py
290 lines (199 loc) · 8.99 KB
/
misc_ot.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import bpy
from . import miscFunc
from bpy.props import (StringProperty, BoolProperty, IntProperty, FloatProperty, FloatVectorProperty, EnumProperty, PointerProperty)
from bpy.types import (Panel, Operator, AddonPreferences, PropertyGroup)
# -----------------------------------------------------------------------------
# Reset all Settings
# -----------------------------------------------------------------------------
class NTZSYM_OT_NtzResetAllSettings(Operator):
"""Tooltip"""
bl_idname = "ntz_sym.resetallsettings"
bl_label = "Neltulz - Symmetry - Reset all Settings"
bl_description = 'Reset All Settings'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return True
def execute(self, context):
scn = context.scene
scn.ntzSym.cutLocation = "DEFAULT"
scn.ntzSym.cutRotation = "DEFAULT"
scn.ntzSym.fillAfterCut = "NO_FILL"
scn.ntzSym.keepModifiers = "NO"
scn.ntzSym.defaultOperatorShowOptions = "UNSET"
scn.ntzSym.removeEmpties = "YES"
scn.ntzSym.removeBisectPlanes = "YES"
return {'FINISHED'}
# END execute()
# END Operator()
# -----------------------------------------------------------------------------
# Write Icon to File
# -----------------------------------------------------------------------------
class NTZSYM_OT_writeicontofile(Operator):
"""Tooltip"""
bl_idname = "ntz_sym.writeicontofile"
bl_label = "Neltulz - Symmetry - Write Icon to File"
bl_description = 'Write Icon to File'
bl_options = {'REGISTER', 'UNDO'}
scale : FloatProperty(
default = 0.3
)
color : FloatVectorProperty (
subtype = "COLOR",
size = 4,
min = 0.0,
max = 1.0,
default = (1.0, 1.0, 1.0, 1.0),
)
name : StringProperty(
default = "Icon",
)
normalize : BoolProperty (
default = True,
)
@classmethod
def poll(cls, context):
return True
def execute(self, context):
scn = context.scene
miscFunc.createIconInfoFromGeo(self, context, self.name, self.color, self.scale, normalize=self.normalize)
return {'FINISHED'}
# END execute()
# END Operator()
# -----------------------------------------------------------------------------
# Apply or Remove Mirror Modifier
# -----------------------------------------------------------------------------
class NTZSYM_OT_applyorremovemodifier(Operator):
"""Tooltip"""
bl_idname = "ntz_sym.applyorremovemodifier"
bl_label = "Neltulz - Symmetry - Remove or Apply Mirror Modifier"
bl_description = 'Remove Mirror Modifier'
bl_options = {'REGISTER', 'UNDO'}
tooltip : StringProperty(options={'HIDDEN'})
method_List = [
("APPLY", "Apply", "", "", 0),
("REMOVE", "Remove", "", "", 1),
]
method : EnumProperty (
items = method_List,
name = "Method",
description = "Apply or Remove modifier",
default = "APPLY"
)
removeEmpty : BoolProperty (
name = "Remove Empty",
default = True,
)
removeBisectPlane : BoolProperty (
name = "Remove Bisect Plane",
default = True,
)
#END Operator Properties
@classmethod
def description(cls, context, properties):
return properties.tooltip
#END description()
@classmethod
def poll(cls, context):
return True
def execute(self, context):
scn = context.scene
modeAtBegin = "OBJECT" #declare
try: modeAtBegin = bpy.context.object.mode
except: pass
activeObj = context.view_layer.objects.active
selObjs = set(context.selected_objects)
if modeAtBegin == "EDIT":
editModeObjs = set(bpy.context.objects_in_mode)
#combine selObjs and editModeObjs (useful for applying/removing modifiers in edit mode)
selObjs = selObjs.union(editModeObjs)
objsToRemove = set()
for obj in selObjs:
#check if mirrorParent exists on empty or bisectPlane
mirrorParent = getattr(obj, "mirrorParent", None)
if mirrorParent is not None:
mirrorModifier = miscFunc.findModifier(obj=mirrorParent, modifierType='MIRROR')
bisectModifier = miscFunc.findModifier(obj=mirrorParent, modifierType='BOOLEAN', modifierName='Neltulz - Bisect')
mirrorBisectPlane = None #declare
if bisectModifier is not None:
mirrorBisectPlane = bisectModifier.object
if self.method == "REMOVE":
mirrorParent.modifiers.remove(bisectModifier)
elif self.method == "APPLY":
context.view_layer.objects.active = mirrorParent
bpy.ops.object.mode_set(mode='OBJECT') #Switch to object mode
bpy.ops.object.modifier_apply(modifier=bisectModifier.name)
if modeAtBegin == "EDIT":
bpy.ops.object.mode_set(mode='EDIT') #Switch to edit mode
mirrorEmpty = None #declare
if mirrorModifier is not None:
mirrorEmpty = mirrorModifier.mirror_object
if self.method == "REMOVE":
mirrorParent.modifiers.remove(mirrorModifier)
elif self.method == "APPLY":
context.view_layer.objects.active = mirrorParent
bpy.ops.object.mode_set(mode='OBJECT') #Switch to object mode
bpy.ops.object.modifier_apply(modifier=mirrorModifier.name)
if modeAtBegin == "EDIT":
bpy.ops.object.mode_set(mode='EDIT') #Switch to edit mode
if mirrorEmpty is not None:
if self.removeEmpty:
objsToRemove.add(mirrorEmpty)
if mirrorBisectPlane is not None:
if self.removeBisectPlane:
objsToRemove.add(mirrorBisectPlane)
#check if object has a bisect(boolean) modifier
bisectModifier = miscFunc.findModifier(obj=obj, modifierType='BOOLEAN', modifierName='Neltulz - Bisect')
if bisectModifier is not None:
mirrorBisectPlane = None #declare
if bisectModifier is not None:
mirrorBisectPlane = bisectModifier.object
if self.method == "REMOVE":
obj.modifiers.remove(bisectModifier)
if self.method == "APPLY":
context.view_layer.objects.active = obj
bpy.ops.object.mode_set(mode='OBJECT') #Switch to object mode
bpy.ops.object.modifier_apply(modifier=bisectModifier.name)
if modeAtBegin == "EDIT":
bpy.ops.object.mode_set(mode='EDIT') #Switch to edit mode
if mirrorBisectPlane is not None:
if self.removeBisectPlane:
objsToRemove.add(mirrorBisectPlane)
#check if object has a mirror modifier
mirrorModifier = miscFunc.findModifier(obj=obj, modifierType='MIRROR')
if mirrorModifier is not None:
mirrorEmpty = None #declare
if mirrorModifier is not None:
mirrorEmpty = mirrorModifier.mirror_object
if self.method == "REMOVE":
obj.modifiers.remove(mirrorModifier)
elif self.method == "APPLY":
context.view_layer.objects.active = obj
bpy.ops.object.mode_set(mode='OBJECT') #Switch to object mode
bpy.ops.object.modifier_apply(modifier=mirrorModifier.name)
if modeAtBegin == "EDIT":
bpy.ops.object.mode_set(mode='EDIT') #Switch to edit mode
if mirrorEmpty is not None:
if self.removeEmpty:
objsToRemove.add(mirrorEmpty)
for obj in objsToRemove:
bpy.data.objects.remove(obj, do_unlink=True)
return {'FINISHED'}
# END execute()
def invoke(self, context, event):
scn = context.scene
if event.ctrl:
self.removeEmpty = False
self.removeBisectPlane = False
else:
if scn.ntzSym.removeEmpties in ["UNSET", "YES"]:
self.removeEmpty = True
else:
self.removeEmpty = False
if scn.ntzSym.removeBisectPlanes in ["UNSET", "YES"]:
self.removeBisectPlane = True
else:
self.removeBisectPlane = False
return self.execute(context)
# END invoke()
# END Operator()