Guest User

blender mirror modifier

a guest
Apr 21st, 2025
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.33 KB | Source Code | 0 0
  1. bl_info = {
  2.     "name": "Set Default Mirror Modifier Merge Distance",
  3.     "author": "ggthb",
  4.     "version": (1, 0),
  5.     "blender": (3, 0, 0),
  6.     "location": "Modifiers > Mirror Modifier",
  7.     "description": "Sets the default merge threshold for the Mirror Modifier to 0.0001 meters",
  8.     "category": "Modifiers",
  9. }
  10.  
  11. import bpy
  12. from bpy.app.handlers import persistent
  13. from bpy.types import Operator
  14.  
  15. # Function to set the merge threshold for Mirror Modifiers
  16. def update_mirror_modifier_merge_threshold(modifier):
  17.     if modifier.type == 'MIRROR':
  18.         modifier.merge_threshold = 0.0001
  19.  
  20. # Handler to apply settings to new modifiers
  21. @persistent
  22. def on_modifier_add(scene):
  23.     # Iterate over all objects in bpy.data.objects
  24.     for obj in bpy.data.objects:
  25.         for modifier in obj.modifiers:
  26.             # Set merge threshold for new or unmodified Mirror Modifiers
  27.             if modifier.type == 'MIRROR' and modifier.merge_threshold != 0.0001:
  28.                 modifier.merge_threshold = 0.0001
  29.  
  30. # Operator to apply the setting to existing Mirror Modifiers
  31. class OBJECT_OT_SetMirrorMergeThreshold(Operator):
  32.     bl_idname = "object.set_mirror_merge_threshold"
  33.     bl_label = "Set Mirror Merge Threshold"
  34.     bl_description = "Sets the merge threshold to 0.0001m for all Mirror Modifiers in the scene"
  35.    
  36.     def execute(self, context):
  37.         for obj in bpy.data.objects:
  38.             for modifier in obj.modifiers:
  39.                 update_mirror_modifier_merge_threshold(modifier)
  40.         # Save user preferences to persist changes
  41.         bpy.ops.wm.save_userpref()
  42.         return {'FINISHED'}
  43.  
  44. def register():
  45.     # Register the operator
  46.     bpy.utils.register_class(OBJECT_OT_SetMirrorMergeThreshold)
  47.     # Append the handler to check for new modifiers
  48.     bpy.app.handlers.depsgraph_update_post.append(on_modifier_add)
  49.     # Apply to existing modifiers on startup
  50.     for obj in bpy.data.objects:
  51.         for modifier in obj.modifiers:
  52.             update_mirror_modifier_merge_threshold(modifier)
  53.  
  54. def unregister():
  55.     # Unregister the operator
  56.     bpy.utils.unregister_class(OBJECT_OT_SetMirrorMergeThreshold)
  57.     # Remove the handler
  58.     if on_modifier_add in bpy.app.handlers.depsgraph_update_post:
  59.         bpy.app.handlers.depsgraph_update_post.remove(on_modifier_add)
  60.  
  61. if __name__ == "__main__":
  62.     register()
Tags: blender
Advertisement
Add Comment
Please, Sign In to add comment