[Bf-extensions-cvs] [3d2d8234] master: Addon: BSurfaces: Refactoring. Fixed bugs

Spivak Vladimir cwolf3d noreply at git.blender.org
Thu Oct 17 15:53:36 CEST 2019


Commit: 3d2d8234a564b52a6dcbbb25b28632906e09f5e4
Author: Spivak Vladimir (cwolf3d)
Date:   Thu Oct 17 16:53:06 2019 +0300
Branches: master
https://developer.blender.org/rBA3d2d8234a564b52a6dcbbb25b28632906e09f5e4

Addon: BSurfaces: Refactoring. Fixed bugs

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

M	mesh_bsurfaces.py

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

diff --git a/mesh_bsurfaces.py b/mesh_bsurfaces.py
index 568ebae4..504e17de 100644
--- a/mesh_bsurfaces.py
+++ b/mesh_bsurfaces.py
@@ -1429,7 +1429,6 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
         me.from_pydata(all_verts_coords, all_edges, [])
         ob = object_utils.object_data_add(context, me)
 
-        bpy.ops.object.editmode_toggle('INVOKE_REGION_WIN')
         bpy.ops.object.select_all('INVOKE_REGION_WIN', action='DESELECT')
         ob.select_set(True)
         bpy.context.view_layer.objects.active = ob
@@ -1604,7 +1603,6 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
         ob_surface = object_utils.object_data_add(context, me_surf)
 
         # Delete final points temporal object
-        bpy.ops.object.editmode_toggle('INVOKE_REGION_WIN')
         bpy.ops.object.delete({"selected_objects": [final_points_ob]})
 
         # Delete isolated verts if there are any
@@ -3100,14 +3098,13 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
     
     def execute(self, context):
         
-        bpy.ops.object.mode_set('INVOKE_REGION_WIN', mode='OBJECT')
-        
-        global global_mesh_object
-        
-        bsurfaces_props = bpy.context.scene.bsurfaces
-        self.main_object = bpy.data.objects[global_mesh_object]
+        if bpy.ops.object.mode_set.poll():
+            bpy.ops.object.mode_set('INVOKE_REGION_WIN', mode='OBJECT')
 
         try:
+            global global_mesh_object
+            bsurfaces_props = bpy.context.scene.bsurfaces
+            self.main_object = bpy.data.objects[global_mesh_object]
             self.main_object.select_set(True)
         except:
             self.report({'WARNING'}, "Specify the name of the object with retopology")
@@ -3159,10 +3156,6 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
                 strokes_for_rectangular_surface = True
                 strokes_for_crosshatch = False
 
-            bpy.ops.object.select_all('INVOKE_REGION_WIN', action='DESELECT')
-            self.main_object.select_set(True)
-            bpy.context.view_layer.objects.active = self.main_object
-
             bpy.ops.object.editmode_toggle('INVOKE_REGION_WIN')
 
             if strokes_for_rectangular_surface:
@@ -3265,28 +3258,14 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
                 global global_gpencil_object
                 gp = bpy.data.objects[global_gpencil_object]
                 self.original_curve = conver_gpencil_to_curve(self, context, gp, 'GPensil')
-                gplayer_prefix_translated = bpy.app.translations.pgettext_data('GP_Layer')
-                for ob in bpy.context.selected_objects:
-                    if ob != bpy.context.view_layer.objects.active and \
-                       ob.name.startswith((gplayer_prefix_translated, 'GP_Layer')):
-                        self.original_curve = ob
                 self.using_external_curves = False
                 
-                bpy.ops.object.editmode_toggle('INVOKE_REGION_WIN')
-                
             elif self.strokes_type == "GP_ANNOTATION":
                 # Convert grease pencil strokes to curve
                 gp = bpy.data.grease_pencils["Annotations"]
                 self.original_curve = conver_gpencil_to_curve(self, context, gp, 'Annotation')
-                gplayer_prefix_translated = bpy.app.translations.pgettext_data('GP_Layer')
-                for ob in bpy.context.selected_objects:
-                    if ob != bpy.context.view_layer.objects.active and \
-                       ob.name.startswith((gplayer_prefix_translated, 'GP_Layer')):
-                        self.original_curve = ob
                 self.using_external_curves = False
                 
-                bpy.ops.object.editmode_toggle('INVOKE_REGION_WIN')
-                
             elif self.strokes_type == "EXTERNAL_CURVE":
                 global global_curve_object
                 self.original_curve = bpy.data.objects[global_curve_object]
@@ -3298,11 +3277,6 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
                 if o.name.find("SURFSKIO_") != -1:
                     bpy.ops.object.delete({"selected_objects": [o]})
 
-            try:
-                self.original_curve.select_set(True)
-            except:
-                self.report({'WARNING'}, "Specify the name of the object with curve")
-                return{"CANCELLED"}
             bpy.context.view_layer.objects.active = self.original_curve
 
             bpy.ops.object.duplicate('INVOKE_REGION_WIN')
@@ -3441,32 +3415,28 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
             # Delete temporary strokes curve object
             bpy.ops.object.delete({"selected_objects": [self.temporary_curve]})
             
-            # If "Keep strokes" option is not active, delete original strokes curve object
-            if not self.stopping_errors or self.is_crosshatch:
-                bpy.ops.object.delete({"selected_objects": [self.original_curve]})
-
-            # Delete grease pencil strokes
-            if self.strokes_type == "GP_STROKES" and not self.stopping_errors:
-                try:
-                    bpy.context.scene.bsurfaces.SURFSK_gpencil.data.layers.active.clear()
-                except:
-                    pass
-                
-            # Delete annotation strokes
-            if self.strokes_type == "GP_ANNOTATION" and not self.stopping_errors:
-                try:
-                    bpy.data.grease_pencils[0].layers.active.clear()
-                except:
-                    pass
-            
-            bpy.ops.object.select_all('INVOKE_REGION_WIN', action='DESELECT')
-            self.main_object.select_set(True)
-            bpy.context.view_layer.objects.active = self.main_object
-            
             # Set again since "execute()" will turn it again to its initial value
             self.execute(context)
 
             if not self.stopping_errors:
+                # Delete grease pencil strokes
+                if self.strokes_type == "GP_STROKES":
+                    try:
+                        bpy.context.scene.bsurfaces.SURFSK_gpencil.data.layers.active.clear()
+                    except:
+                        pass
+                    
+                # Delete annotation strokes
+                elif self.strokes_type == "GP_ANNOTATION":
+                    try:
+                        bpy.data.grease_pencils[0].layers.active.clear()
+                    except:
+                        pass
+                
+                bpy.ops.object.editmode_toggle('INVOKE_REGION_WIN')
+                bpy.ops.object.delete({"selected_objects": [self.original_curve]})
+                bpy.ops.object.editmode_toggle('INVOKE_REGION_WIN')
+                    
                 return {"FINISHED"}
             else:
                 return{"CANCELLED"}
@@ -3535,8 +3505,6 @@ class GPENCIL_OT_SURFSK_init(Operator):
             bpy.ops.object.select_all('INVOKE_REGION_WIN', action='DESELECT')
             mesh = bpy.data.meshes.new('BSurfaceMesh')
             mesh_object = object_utils.object_data_add(context, mesh)
-            bm = bmesh.from_edit_mesh(mesh)
-            bmesh.update_edit_mesh(mesh)
             mesh_object.select_set(True)
             bpy.context.view_layer.objects.active = mesh_object
             
@@ -3615,7 +3583,8 @@ class GPENCIL_OT_SURFSK_add_modifiers(Operator):
     
         bs = bpy.context.scene.bsurfaces
     
-        bpy.ops.object.mode_set('INVOKE_REGION_WIN', mode='OBJECT')
+        if bpy.ops.object.mode_set.poll():
+            bpy.ops.object.mode_set('INVOKE_REGION_WIN', mode='OBJECT')
         
         if bs.SURFSK_mesh == None:
             self.report({'ERROR_INVALID_INPUT'}, "Please select Mesh of BSurface or click Initialize")
@@ -3691,7 +3660,8 @@ class GPENCIL_OT_SURFSK_edit_surface(Operator):
     bl_options = {'REGISTER', 'UNDO'}
 
     def execute(self, context):
-        bpy.ops.object.mode_set('INVOKE_REGION_WIN', mode='OBJECT')
+        if bpy.ops.object.mode_set.poll():
+            bpy.ops.object.mode_set('INVOKE_REGION_WIN', mode='OBJECT')
         bpy.ops.object.select_all('INVOKE_REGION_WIN', action='DESELECT')
         bpy.context.scene.bsurfaces.SURFSK_mesh.select_set(True)
         bpy.context.view_layer.objects.active = bpy.context.scene.bsurfaces.SURFSK_mesh
@@ -3718,7 +3688,8 @@ class GPENCIL_OT_SURFSK_add_strokes(Operator):
     bl_options = {'REGISTER', 'UNDO'}
 
     def execute(self, context):
-        bpy.ops.object.mode_set('INVOKE_REGION_WIN', mode='OBJECT')
+        if bpy.ops.object.mode_set.poll():
+            bpy.ops.object.mode_set('INVOKE_REGION_WIN', mode='OBJECT')
         bpy.ops.object.select_all('INVOKE_REGION_WIN', action='DESELECT')
 
         bpy.context.scene.bsurfaces.SURFSK_gpencil.select_set(True)
@@ -3784,34 +3755,24 @@ class GPENCIL_OT_SURFSK_annotation_to_curves(Operator):
 
     def execute(self, context):
 
-        bpy.ops.object.mode_set('INVOKE_REGION_WIN', mode='OBJECT')
+        if bpy.ops.object.mode_set.poll():
+            bpy.ops.object.mode_set('INVOKE_REGION_WIN', mode='OBJECT')
 
         # Convert annotation to curve
-        conver_gpencil_to_curve(self, context, None, 'Annotation')
-        for ob in bpy.context.selected_objects:
-            if ob != bpy.context.view_layer.objects.active and ob.name.startswith("GP_Layer"):
-                ob_gp_strokes = ob
-
-        ob_gp_strokes = bpy.context.object
+        curve = conver_gpencil_to_curve(self, context, None, 'Annotation')
 
-        # Delete annotation strokes
-        try:
-            bpy.data.grease_pencils[0].layers.active.clear()
-        except:
-            pass
-
-        # Clean up curves
-        bpy.ops.object.editmode_toggle('INVOKE_REGION_WIN')
-        bpy.ops.object.select_all('INVOKE_REGION_WIN', action='DESELECT')
-        ob_gp_strokes.select_set(True)
-        bpy.context.view_layer.objects.active = ob_gp_strokes
+        if curve != None:
+            # Delete annotation strokes
+            try:
+                bpy.data.grease_pencils[0].layers.active.clear()
+            except:
+                pass
 
-        curve_crv = ob_gp_strokes.data
-        bpy.ops.object.editmode_toggle('INVOKE_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list