[Bf-extensions-cvs] [52793245] master: Auto Mirror: Cleanup, use a property group

lijenstina noreply at git.blender.org
Thu Jul 13 19:51:11 CEST 2017


Commit: 527932454e078bd7a90078858c17f600d9ec8a1d
Author: lijenstina
Date:   Thu Jul 13 19:50:22 2017 +0200
Branches: master
https://developer.blender.org/rBA527932454e078bd7a90078858c17f600d9ec8a1d

Auto Mirror: Cleanup, use a property group

Bumped version to 2.4.2
Pep8 cleanup
Moved scene properties to a property group
access it through context.scene.auto_mirror
remove the properties upon unregister

Add poll checks for Mesh objects to operators
Add missing operator description

Remove the draw function from the AutoMirror operator
since it is not used and enabling Undo will not work
in this case, since depending on the initial settings
it can produce unwanted results

===================================================================

M	mesh_auto_mirror.py

===================================================================

diff --git a/mesh_auto_mirror.py b/mesh_auto_mirror.py
index 84128072..032bff37 100644
--- a/mesh_auto_mirror.py
+++ b/mesh_auto_mirror.py
@@ -1,208 +1,182 @@
-######################################################################################################
-# An simple add-on to auto cut in two and mirror an object                                           #
-# Actualy partialy uncommented (see further version)                                                 #
-# Author: Lapineige                                                                                  #
-# License: GPL v3                                                                                    #
-######################################################################################################
-
-
-############# Add-on description (used by Blender)
+# ########################################################### #
+#   An simple add-on to auto cut in two and mirror an object  #
+#   Actualy partialy uncommented (see further version)        #
+#   Author: Lapineige                                         #
+#   License: GPL v3                                           #
+# ########################################################### #
 
 bl_info = {
     "name": "Auto Mirror",
-    "description": "Super fast cutting and mirroring for mesh",
+    "description": "Super fast cutting and mirroring for Mesh objects",
     "author": "Lapineige",
-    "version": (2, 4, 1),
+    "version": (2, 4, 2),
     "blender": (2, 7, 1),
     "location": "View 3D > Toolbar > Tools tab > AutoMirror (panel)",
     "warning": "",
-    "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Modeling/AutoMirror",
-    "tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
+    "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/"
+                "Py/Scripts/Modeling/AutoMirror",
     "category": "Mesh"}
 
 
 import bpy
+from bpy.props import (
+        BoolProperty,
+        EnumProperty,
+        FloatProperty,
+        PointerProperty,
+        )
+from bpy.types import (
+        Operator,
+        Panel,
+        PropertyGroup,
+        )
 from mathutils import Vector
 
-bpy.types.Scene.AutoMirror_axis = bpy.props.EnumProperty(
-            items = [
-            ("x", "X", "", 1),
-            ("y", "Y", "", 2),
-            ("z", "Z", "", 3)],
-            description="Axis used by the mirror modifier"
-            )
-bpy.types.Scene.AutoMirror_orientation = bpy.props.EnumProperty(
-            items = [
-            ("positive","Positive", "", 1),
-            ("negative", "Negative", "", 2)],
-            description="Choose the side along the axis of the editable part (+/- coordinates)"
-            )
-bpy.types.Scene.AutoMirror_threshold = bpy.props.FloatProperty(
-            default= 0.001,
-            min= 0.001,
-            description="Vertices closer than this distance are merged on the loopcut"
-            )
-bpy.types.Scene.AutoMirror_toggle_edit = bpy.props.BoolProperty(
-            default= True,
-            description="If not in edit mode, change mode to edit"
-            )
-bpy.types.Scene.AutoMirror_cut = bpy.props.BoolProperty(
-            default= True,
-            description="If enabeled, cut the mesh in two parts and mirror it. If not, just make a loopcut"
-            )
-bpy.types.Scene.AutoMirror_clipping = bpy.props.BoolProperty(
-            default=True
-            )
-bpy.types.Scene.AutoMirror_use_clip = bpy.props.BoolProperty(
-            default=True,
-            description="Use clipping for the mirror modifier"
-            )
-bpy.types.Scene.AutoMirror_show_on_cage = bpy.props.BoolProperty(
-            default=True,
-            description="Enable to edit the cage (it's the classical modifier's option)"
-            )
-bpy.types.Scene.AutoMirror_apply_mirror = bpy.props.BoolProperty(
-            description="Apply the mirror modifier (useful to symmetrise the mesh)"
-            )
-
-############### Operator
 
-class AlignVertices(bpy.types.Operator):
-    """  """
+# Operators
+class AlignVertices(Operator):
     bl_idname = "object.align_vertices"
-    bl_label = "Align Vertices on 1 Axis"
+    bl_label = "Align Vertices on an Axis"
+    bl_description = ("Align Vertices on an Axis\n"
+                      "Needs an Active Mesh Object")
 
     @classmethod
     def poll(cls, context):
-        return True
+        obj = context.active_object
+        return obj and obj.type == "MESH"
 
     def execute(self, context):
-        bpy.ops.object.mode_set(mode = 'OBJECT')
+        auto_m = context.scene.auto_mirror
+        bpy.ops.object.mode_set(mode='OBJECT')
 
-        x1,y1,z1 = bpy.context.scene.cursor_location
+        x1, y1, z1 = bpy.context.scene.cursor_location
         bpy.ops.view3d.snap_cursor_to_selected()
 
-        x2,y2,z2 = bpy.context.scene.cursor_location
+        x2, y2, z2 = bpy.context.scene.cursor_location
 
-        bpy.context.scene.cursor_location[0],bpy.context.scene.cursor_location[1],bpy.context.scene.cursor_location[2]  = 0,0,0
+        bpy.context.scene.cursor_location[0], \
+        bpy.context.scene.cursor_location[1], \
+        bpy.context.scene.cursor_location[2] = 0, 0, 0
 
-        #Vertices coordinate to 0 (local coordinate, so on the origin)
+        # Vertices coordinate to 0 (local coordinate, so on the origin)
         for vert in bpy.context.object.data.vertices:
             if vert.select:
-                if bpy.context.scene.AutoMirror_axis == 'x':
+                if auto_m.axis == 'x':
                     axis = 0
-                elif bpy.context.scene.AutoMirror_axis == 'y':
+                elif auto_m.axis == 'y':
                     axis = 1
-                elif bpy.context.scene.AutoMirror_axis == 'z':
+                elif auto_m.axis == 'z':
                     axis = 2
                 vert.co[axis] = 0
-        #
-        bpy.context.scene.cursor_location = x2,y2,z2
 
+        bpy.context.scene.cursor_location = x2, y2, z2
         bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
 
-        bpy.context.scene.cursor_location = x1,y1,z1
+        bpy.context.scene.cursor_location = x1, y1, z1
+        bpy.ops.object.mode_set(mode='EDIT')
 
-        bpy.ops.object.mode_set(mode = 'EDIT')
         return {'FINISHED'}
 
-class AutoMirror(bpy.types.Operator):
-    """ Automatically cut an object along an axis """
+
+class AutoMirror(Operator):
     bl_idname = "object.automirror"
     bl_label = "AutoMirror"
-    bl_options = {'REGISTER'} # 'UNDO' ?
+    bl_description = ("Automatically cut an object along an axis\n"
+                      "Needs an Active Mesh Object")
+    bl_options = {'REGISTER'}
 
     @classmethod
     def poll(cls, context):
-        return True
-
-    def draw(self, context):
-        layout = self.layout
-        if bpy.context.object and bpy.context.object.type == 'MESH':
-            layout.prop(context.scene, "AutoMirror_axis", text="Mirror axis")
-            layout.prop(context.scene, "AutoMirror_orientation", text="Orientation")
-            layout.prop(context.scene, "AutoMirror_threshold", text="Threshold")
-            layout.prop(context.scene, "AutoMirror_toggle_edit", text="Toggle edit")
-            layout.prop(context.scene, "AutoMirror_cut", text="Cut and mirror")
-            if bpy.context.scene.AutoMirror_cut:
-                layout.prop(context.scene, "AutoMirror_clipping", text="Clipping")
-                layout.prop(context.scene, "AutoMirror_apply_mirror", text="Apply mirror")
-        else:
-            layout.label(icon="ERROR", text="No mesh selected")
+        obj = context.active_object
+        return obj and obj.type == "MESH"
 
     def get_local_axis_vector(self, context, X, Y, Z, orientation):
         loc = context.object.location
-        bpy.ops.object.mode_set(mode="OBJECT") # Needed to avoid to translate vertices
+        bpy.ops.object.mode_set(mode="OBJECT")  # Needed to avoid to translate vertices
 
-        v1 = Vector((loc[0],loc[1],loc[2]))
+        v1 = Vector((loc[0], loc[1], loc[2]))
         bpy.ops.transform.translate(
-            value=(X*orientation, Y*orientation, Z*orientation),
-            constraint_axis=((X==1), (Y==1), (Z==1)),
-            constraint_orientation='LOCAL')
-        v2 = Vector((loc[0],loc[1],loc[2]))
+                value=(X * orientation, Y * orientation, Z * orientation),
+                constraint_axis=((X == 1), (Y == 1), (Z == 1)),
+                constraint_orientation='LOCAL'
+                )
+        v2 = Vector((loc[0], loc[1], loc[2]))
         bpy.ops.transform.translate(
-            value=(-X*orientation, -Y*orientation, -Z*orientation),
-            constraint_axis=((X==1), (Y==1), (Z==1)),
-            constraint_orientation='LOCAL')
+                value=(-X * orientation, -Y * orientation, -Z * orientation),
+                constraint_axis=((X == 1), (Y == 1), (Z == 1)),
+                constraint_orientation='LOCAL'
+                )
 
         bpy.ops.object.mode_set(mode="EDIT")
-        return v2-v1
+        return v2 - v1
 
     def execute(self, context):
-        X,Y,Z = 0,0,0
-        if bpy.context.scene.AutoMirror_axis == 'x':
+        auto_m = context.scene.auto_mirror
+
+        X, Y, Z = 0, 0, 0
+        if auto_m.axis == 'x':
             X = 1
-        elif bpy.context.scene.AutoMirror_axis == 'y':
+        elif auto_m.axis == 'y':
             Y = 1
-        elif bpy.context.scene.AutoMirror_axis == 'z':
+        elif auto_m.axis == 'z':
             Z = 1
 
-        current_mode = bpy.context.object.mode # Save the current mode
+        current_mode = bpy.context.object.mode    # Save the current mode
 
         if bpy.context.object.mode != "EDIT":
-            bpy.ops.object.mode_set(mode="EDIT") # Go to edit mode
-        bpy.ops.mesh.select_all(action='SELECT') # Select all the vertices
-        if bpy.context.scene.AutoMirror_orientation == 'positive':
+            bpy.ops.object.mode_set(mode="EDIT")  # Go to edit mode
+
+        bpy.ops.mesh.select_all(action='SELECT')  # Select all the vertices
+        if auto_m.orientation == 'positive':
             orientation = 1
         else:
   

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list