forked from jayanam/fast-carve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfc_unbevel_op.py
67 lines (47 loc) · 2.25 KB
/
fc_unbevel_op.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
import bpy
from bpy.types import Operator
class FC_UnBevelOperator(Operator):
bl_idname = "object.unbevel"
bl_label = "Unbevel an object"
bl_description = "Un-Bevels selected objects"
bl_options = {'REGISTER', 'UNDO'}
def get_display(mode):
if mode == "OBJECT":
return "Clear Sharp & Bevel"
else:
return "Clear sharp Edges"
@classmethod
def poll(cls, context):
return len(context.selected_objects) > 0
def execute(self, context):
active_obj = bpy.context.scene.objects.active
mode = context.active_object.mode
# Sharpen and bevel in object mode
if(mode == "OBJECT"):
# We know that we are in object mode
# cause the operator is for OM only
for target_obj in context.selected_objects:
bpy.context.scene.objects.active = target_obj
# Set flat shading for the target object
bpy.ops.object.shade_flat()
# Reset the data from autosmooth
bpy.context.object.data.use_auto_smooth = False
# Remove the bevel modifier if exists
modifier_to_remove = target_obj.modifiers.get("Bevel")
if(not modifier_to_remove is None):
target_obj.modifiers.remove(modifier_to_remove)
# switch to edit mode and select sharp edges
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.mesh.edges_select_sharp()
# Clear the sharp edges
bpy.ops.transform.edge_bevelweight(value=-1.0)
bpy.ops.mesh.mark_sharp(clear=True)
# Back to object mode
bpy.ops.object.editmode_toggle()
else:
# Clear the selected edges
bpy.ops.transform.edge_bevelweight(value=-1.0)
bpy.ops.mesh.mark_sharp(clear=True)
bpy.context.scene.objects.active = active_obj
return {'FINISHED'}