Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # BLENDER 2.9x+ addon to evenly spread out loose parts of a single object in edit mode.
- # written by Testure in response to a RCS thread: https://blender.community/c/rightclickselect/XQYk/
- # INSTALLATION: drop this into your Blender/scripts/startup folder and restart Blender. Operator will be available in edit mode only.
- import bpy
- class MESH_OT_spread_loose(bpy.types.Operator):
- """Evenly spread out loose parts of a single object in edit mode"""
- bl_idname = "mesh.spread_loose"
- bl_label = "Spread Out Loose Parts"
- def __init__(self):
- self.original_origin = None
- def modal(self, context, event):
- # operator's modal is pass through, just listening for FINISH event conditions
- if event.type in { 'LEFTMOUSE', 'RIGHTMOUSE', 'ESC'} and event.value == "RELEASE":
- self.finish(context)
- return {'FINISHED'}
- return {'PASS_THROUGH'}
- @classmethod
- def poll(cls, context):
- return context.mode == 'EDIT_MESH' and len(context.selected_objects) == 1
- def finish(self, context):
- bpy.ops.object.join()
- cursor_matrix = context.scene.cursor.matrix.copy()
- context.scene.cursor.matrix = self.original_origin
- bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')
- context.scene.cursor.matrix = cursor_matrix
- bpy.context.scene.tool_settings.use_transform_pivot_point_align = False
- bpy.ops.object.editmode_toggle()
- def invoke(self, context, event):
- self.original_origin = context.active_object.matrix_world.copy()
- bpy.ops.mesh.separate(type='LOOSE')
- bpy.ops.object.editmode_toggle()
- bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN')
- bpy.context.scene.tool_settings.use_transform_pivot_point_align = True
- bpy.ops.transform.resize('INVOKE_DEFAULT', constraint_axis=(False, False, False))
- context.window_manager.modal_handler_add(self)
- return {'RUNNING_MODAL'}
- def register():
- bpy.utils.register_class(MESH_OT_spread_loose)
- def unregister():
- bpy.utils.unregister_class(MESH_OT_spread_loose)
- if __name__ == "__main__":
- register()
Advertisement
Add Comment
Please, Sign In to add comment