Skip to content

Commit

Permalink
feat: allow profile extrude, screw, mirror, and circularize operators…
Browse files Browse the repository at this point in the history
… to be run from edit mode
  • Loading branch information
tristan-hm committed Jun 30, 2024
1 parent 90d4959 commit 0ece46c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
13 changes: 12 additions & 1 deletion extrusion/profile_extrude.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def do_invoke(self, context, event):

self.extrusion_length_input_stream = new_stream()
self.offset_input_stream = new_stream()
self.edit_mode = context.mode == 'EDIT_MESH'

self.target_object = context.active_object

Expand Down Expand Up @@ -160,7 +161,7 @@ def do_invoke(self, context, event):

@classmethod
def poll(cls, context):
if context.mode == 'OBJECT' and context.object is not None:
if context.mode in {'OBJECT', 'EDIT_MESH'} and context.object is not None:
return len(context.selected_objects) == 1 and context.active_object.type == 'MESH'


Expand Down Expand Up @@ -222,14 +223,24 @@ def add_smooth_shading(self, context):
if not get_preferences().enable_auto_smooth:
return

return_to_edit = False
if self.edit_mode:
bpy.ops.object.mode_set(mode='OBJECT')
return_to_edit = True

if bpy.app.version >= (4, 1, 0):
self.smoothing = add_smooth_by_angle(self.target_object)
if return_to_edit:
bpy.ops.object.mode_set(mode='EDIT')
return

bpy.ops.object.shade_smooth()
self.target_object.data.use_auto_smooth = True
self.target_object.data.auto_smooth_angle = radians(float(get_preferences().default_smoothing_angle))

if return_to_edit:
bpy.ops.object.mode_set(mode='EDIT')


def add_weighting_modifier(self, context):
offset = new_modifier(self.target_object, mod_weighting, 'DISPLACE', rectify=True)
Expand Down
13 changes: 12 additions & 1 deletion extrusion/screw.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def do_invoke(self, context, event):
self.dirty = False
self.target_object = context.active_object
self.object_type = self.target_object.type
self.edit_mode = context.mode == 'EDIT_MESH'

self.axis = 2 # X (0), Y (1), Z (2)
self.offset_axis = 1 # X (0), Y (1), Z (2)
Expand Down Expand Up @@ -194,7 +195,7 @@ def do_invoke(self, context, event):

@classmethod
def poll(cls, context):
if context.mode == 'OBJECT' and context.active_object is not None:
if context.mode in {'OBJECT', 'EDIT_MESH'} and context.active_object is not None:
return len(context.selected_objects) == 1 and context.active_object.type in ['MESH', 'CURVE']


Expand Down Expand Up @@ -238,14 +239,24 @@ def add_smooth_shading(self, context):
if not get_preferences().enable_auto_smooth:
return

return_to_edit = False
if self.edit_mode:
bpy.ops.object.mode_set(mode='OBJECT')
return_to_edit = True

if bpy.app.version >= (4, 1, 0):
add_smooth_by_angle(self.target_object)
if return_to_edit:
bpy.ops.object.mode_set(mode='EDIT')
return

bpy.ops.object.shade_smooth()
self.target_object.data.use_auto_smooth = True
self.target_object.data.auto_smooth_angle = radians(float(get_preferences().default_smoothing_angle))

if return_to_edit:
bpy.ops.object.mode_set(mode='EDIT')


def add_displace_modifier(self, context):
displace = new_modifier(self.target_object, mod_displace, 'DISPLACE', rectify=True)
Expand Down
11 changes: 11 additions & 0 deletions replicate/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def do_invoke(self, context, event):
remove_modifiers_starting_with(context.selected_objects, 'Mirror —')
return {'FINISHED'}

self.edit_mode = context.mode == 'EDIT_MESH'
self.geometry_mode = event.alt
self.early_apply = event.shift
self.geometry_ready = False
Expand All @@ -119,6 +120,10 @@ def do_invoke(self, context, event):
self.report({'ERROR_INVALID_INPUT'}, "The mirror across selected geometry feature cannot be used on curves")
return {'CANCELLED'}

if self.edit_mode and self.geometry_mode:
self.report({'ERROR_INVALID_INPUT'}, "The mirror across selected geometry feature cannot be used in edit mode")
return {'CANCELLED'}

if len(context.selected_objects) >= 2:
self.reference_objs = [obj for obj in context.selected_objects if obj != context.active_object]
self.mirror_obj = context.active_object
Expand Down Expand Up @@ -153,6 +158,9 @@ def poll(cls, context):
if len(context.selected_objects) >= 2 and context.active_object is not None:
return all(obj.type in ['MESH', 'CURVE'] for obj in context.selected_objects if obj.name != context.active_object.name)

if context.mode == 'EDIT_MESH':
return len(context.selected_objects) == 1 and context.active_object is not None and context.active_object.type in ['MESH', 'CURVE']


def set_selection_mode(self, context):
bpy.ops.mesh.select_all(action='DESELECT')
Expand Down Expand Up @@ -344,6 +352,9 @@ def operate(self, context):


def select_reference_objs(self, context):
if self.edit_mode:
return

bpy.ops.object.select_all(action='DESELECT')
for obj in self.reference_objs:
obj.select_set(True)
Expand Down
13 changes: 12 additions & 1 deletion sketch/circularize.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def do_invoke(self, context, event):

self.dirty = False
self.segments = 2
self.edit_mode = context.mode == 'EDIT_MESH'

self.segments_input_stream = new_stream()
self.width_input_stream = new_stream()
Expand Down Expand Up @@ -129,7 +130,7 @@ def do_invoke(self, context, event):

@classmethod
def poll(cls, context):
if context.mode == 'OBJECT' and context.active_object is not None:
if context.mode in {'OBJECT', 'EDIT_MESH'} and context.active_object is not None:
return len(context.selected_objects) == 1 and context.active_object.type == 'MESH'


Expand Down Expand Up @@ -159,14 +160,24 @@ def add_smooth_shading(self, context):
if not get_preferences().enable_auto_smooth:
return

return_to_edit = False
if self.edit_mode:
bpy.ops.object.mode_set(mode='OBJECT')
return_to_edit = True

if bpy.app.version >= (4, 1, 0):
add_smooth_by_angle(self.target_object)
if return_to_edit:
bpy.ops.object.mode_set(mode='EDIT')
return

bpy.ops.object.shade_smooth()
self.target_object.data.use_auto_smooth = True
self.target_object.data.auto_smooth_angle = radians(float(get_preferences().default_smoothing_angle))

if return_to_edit:
bpy.ops.object.mode_set(mode='EDIT')


def add_bevel_modifier(self, context):
bevel = new_modifier(self.target_object, mod_bevel, 'BEVEL', rectify=False)
Expand Down

0 comments on commit 0ece46c

Please sign in to comment.