[Bf-extensions-cvs] [d605104b] master: Add Curve: Extra Objects: addon fix when enabled bpy.context.preferences.edit.use_enter_edit_mode = True

Spivak Vladimir cwolf3d noreply at git.blender.org
Mon Jul 15 22:41:36 CEST 2019


Commit: d605104b9cfbbe2a8683aec775e8d3bf14de3a5c
Author: Spivak Vladimir (cwolf3d)
Date:   Mon Jul 15 23:40:14 2019 +0300
Branches: master
https://developer.blender.org/rBAd605104b9cfbbe2a8683aec775e8d3bf14de3a5c

Add Curve: Extra Objects: addon fix when enabled bpy.context.preferences.edit.use_enter_edit_mode = True

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

M	add_curve_extra_objects/add_curve_aceous_galore.py
M	add_curve_extra_objects/add_curve_braid.py
M	add_curve_extra_objects/add_curve_celtic_links.py
M	add_curve_extra_objects/add_curve_curly.py
M	add_curve_extra_objects/add_curve_simple.py
M	add_curve_extra_objects/add_curve_spirals.py
M	add_curve_extra_objects/add_curve_torus_knots.py

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

diff --git a/add_curve_extra_objects/add_curve_aceous_galore.py b/add_curve_extra_objects/add_curve_aceous_galore.py
index f5cec2fa..95d38902 100644
--- a/add_curve_extra_objects/add_curve_aceous_galore.py
+++ b/add_curve_extra_objects/add_curve_aceous_galore.py
@@ -1460,10 +1460,20 @@ class Curveaceous_galore(Operator, object_utils.AddObjectHelper):
         return context.scene is not None
 
     def execute(self, context):
+        # turn off 'Enter Edit Mode'
+        use_enter_edit_mode = bpy.context.preferences.edit.use_enter_edit_mode
+        bpy.context.preferences.edit.use_enter_edit_mode = False
+        
         # main function
         self.align_matrix = align_matrix(context, self.startlocation)
         main(context, self, self.align_matrix or Matrix())
         
+        if use_enter_edit_mode:
+            bpy.ops.object.mode_set(mode = 'EDIT')
+        
+        # restore pre operator state
+        bpy.context.preferences.edit.use_enter_edit_mode = use_enter_edit_mode
+        
         return {'FINISHED'}
         
     def invoke(self, context, event):
diff --git a/add_curve_extra_objects/add_curve_braid.py b/add_curve_extra_objects/add_curve_braid.py
index 874324a8..16e072d4 100644
--- a/add_curve_extra_objects/add_curve_braid.py
+++ b/add_curve_extra_objects/add_curve_braid.py
@@ -229,6 +229,10 @@ class Braid(Operator):
         col.prop(self, "resolution")
 
     def execute(self, context):
+         # turn off 'Enter Edit Mode'
+        use_enter_edit_mode = bpy.context.preferences.edit.use_enter_edit_mode
+        bpy.context.preferences.edit.use_enter_edit_mode = False
+        
         circle = defaultCircle(self.strandsize)
         context.scene.collection.objects.link(circle)
         braid = awesome_braid(
@@ -244,8 +248,14 @@ class Braid(Operator):
 
         for ob in context.scene.objects:
             ob.select_set(False)
-        #base.select_set(True)
-        #context.scene.objects.active = braid
+        braid.select_set(True)
+        bpy.context.view_layer.objects.active = braid
+        
+        if use_enter_edit_mode:
+            bpy.ops.object.mode_set(mode = 'EDIT')
+        
+        # restore pre operator state
+        bpy.context.preferences.edit.use_enter_edit_mode = use_enter_edit_mode
 
         return {'FINISHED'}
 
diff --git a/add_curve_extra_objects/add_curve_celtic_links.py b/add_curve_extra_objects/add_curve_celtic_links.py
index c5b581fa..87b778fe 100644
--- a/add_curve_extra_objects/add_curve_celtic_links.py
+++ b/add_curve_extra_objects/add_curve_celtic_links.py
@@ -122,6 +122,10 @@ class CelticKnotOperator(Operator):
         layout.prop(self, "geo_bDepth")
 
     def execute(self, context):
+        # turn off 'Enter Edit Mode'
+        use_enter_edit_mode = bpy.context.preferences.edit.use_enter_edit_mode
+        bpy.context.preferences.edit.use_enter_edit_mode = False
+        
         # Cache some values
         s = sin(self.crossing_angle) * self.crossing_strength
         c = cos(self.crossing_angle) * self.crossing_strength
@@ -267,7 +271,11 @@ class CelticKnotOperator(Operator):
             curve_obj.data.bevel_depth = self.geo_bDepth
         except:
             pass
-        #context.scene.objects.active = orig_obj
+        
+        bpy.context.view_layer.objects.active = orig_obj
+        
+        # restore pre operator state
+        bpy.context.preferences.edit.use_enter_edit_mode = use_enter_edit_mode
 
         return {'FINISHED'}
 
diff --git a/add_curve_extra_objects/add_curve_curly.py b/add_curve_extra_objects/add_curve_curly.py
index e904a070..b5243766 100644
--- a/add_curve_extra_objects/add_curve_curly.py
+++ b/add_curve_extra_objects/add_curve_curly.py
@@ -509,6 +509,10 @@ class add_curlycurve(Operator, AddObjectHelper):
         row.prop(self, "shape", expand=True)
 
     def execute(self, context):
+        # turn off 'Enter Edit Mode'
+        use_enter_edit_mode = bpy.context.preferences.edit.use_enter_edit_mode
+        bpy.context.preferences.edit.use_enter_edit_mode = False
+        
         if self.types == 1:
             add_type1(self, context)
         if self.types == 2:
@@ -529,6 +533,12 @@ class add_curlycurve(Operator, AddObjectHelper):
             add_type9(self, context)
         if self.types == 10:
             add_type10(self, context)
+            
+        if use_enter_edit_mode:
+            bpy.ops.object.mode_set(mode = 'EDIT')
+        
+        # restore pre operator state
+        bpy.context.preferences.edit.use_enter_edit_mode = use_enter_edit_mode
 
         return {'FINISHED'}
 
diff --git a/add_curve_extra_objects/add_curve_simple.py b/add_curve_extra_objects/add_curve_simple.py
index bacfe57d..dd560737 100644
--- a/add_curve_extra_objects/add_curve_simple.py
+++ b/add_curve_extra_objects/add_curve_simple.py
@@ -421,38 +421,10 @@ def vertsToPoints(Verts, splineType):
 # ------------------------------------------------------------
 # Main Function
 
-def main(context, self, align_matrix):
+def main(context, self, align_matrix, use_enter_edit_mode):
     # output splineType 'POLY' 'NURBS' 'BEZIER'
     splineType = self.outputType
     
-    # create object
-    if bpy.context.mode == 'EDIT_CURVE':
-        Curve = context.active_object
-        newSpline = Curve.data.splines.new(type=splineType)          # spline
-    else:
-        name = self.Simple_Type  # Type as name
-    
-        dataCurve = bpy.data.curves.new(name, type='CURVE')  # curve data block
-        newSpline = dataCurve.splines.new(type=splineType)          # spline
-
-        # create object with new Curve
-        Curve = object_utils.object_data_add(context, dataCurve, operator=self)  # place in active scene
-        Curve.matrix_world = align_matrix  # apply matrix
-        Curve.rotation_euler = self.Simple_rotation_euler
-    
-    # set newSpline Options
-    newSpline.use_cyclic_u = self.use_cyclic_u
-    newSpline.use_endpoint_u = self.endp_u
-    newSpline.order_u = self.order_u
-    
-    # set curve Options
-    Curve.data.dimensions = self.shape
-    Curve.data.use_path = True
-    if self.shape == '3D':
-        Curve.data.fill_mode = 'FULL'
-    else:
-        Curve.data.fill_mode = 'BOTH'
-    
     sides = abs(int((self.Simple_endangle - self.Simple_startangle) / 90))
 
     # get verts
@@ -547,6 +519,22 @@ def main(context, self, align_matrix):
     # turn verts into array
     vertArray = vertsToPoints(verts, splineType)
     
+    # create object
+    if bpy.context.mode == 'EDIT_CURVE':
+        Curve = context.active_object
+        newSpline = Curve.data.splines.new(type=splineType)          # spline
+    else:
+        name = self.Simple_Type  # Type as name
+    
+        dataCurve = bpy.data.curves.new(name, type='CURVE')  # curve data block
+        newSpline = dataCurve.splines.new(type=splineType)          # spline
+
+        # create object with new Curve
+        Curve = object_utils.object_data_add(context, dataCurve, operator=self)  # place in active scene
+        Curve.matrix_world = align_matrix  # apply matrix
+        Curve.rotation_euler = self.Simple_rotation_euler
+        Curve.select_set(True)
+    
     for spline in Curve.data.splines:
         if spline.type == 'BEZIER':
             for point in spline.bezier_points:
@@ -809,7 +797,18 @@ def main(context, self, align_matrix):
         bpy.ops.transform.rotate(value = self.Simple_rotation_euler[1], orient_axis = 'Y')
         bpy.ops.transform.rotate(value = self.Simple_rotation_euler[2], orient_axis = 'Z')
     
-    return
+    # set newSpline Options
+    newSpline.use_cyclic_u = self.use_cyclic_u
+    newSpline.use_endpoint_u = self.endp_u
+    newSpline.order_u = self.order_u
+    
+    # set curve Options
+    Curve.data.dimensions = self.shape
+    Curve.data.use_path = True
+    if self.shape == '3D':
+        Curve.data.fill_mode = 'FULL'
+    else:
+        Curve.data.fill_mode = 'BOTH'
 
 # ### MENU append ###
 def Simple_curve_edit_menu(self, context):
@@ -1286,9 +1285,20 @@ class Simple(Operator, object_utils.AddObjectHelper):
         return context.scene is not None
 
     def execute(self, context):
+        
+        # turn off 'Enter Edit Mode'
+        use_enter_edit_mode = bpy.context.preferences.edit.use_enter_edit_mode
+        bpy.context.preferences.edit.use_enter_edit_mode = False
+        
         # main function
         self.align_matrix = align_matrix(context, self.Simple_startlocation)
-        main(context, self, self.align_matrix)
+        main(context, self, self.align_matrix, use_enter_edit_mode)
+        
+        if use_enter_edit_mode:
+            bpy.ops.object.mode_set(mode = 'EDIT')
+        
+        # restore pre operator state
+        bpy.context.preferences.edit.use_enter_edit_mode = use_enter_edit_mode
 
         return {'FINISHED'}
 
diff --git a/add_curve_extra_objects/add_curve_spirals.py b/add_curve_extra_objects/add_curve_spirals.py
index 3cbb8410..c669642f 100644
--- a/add_curve_extra_objects/add_curve_spirals.py
+++ b/add_curve_extra_objects/add_curve_spirals.py
@@ -534,9 +534,19 @@ class CURVE_OT_spirals(Operator):
         return context.scene is not None
 
     def execute(self, context):
+        # turn off 'Enter Edit Mode'
+        use_enter_edit_mode = bpy.context.preferences.edit.use_enter_edit_mode
+        bpy.context.preferences.edit.use_enter_edit_mode = False
+        
         time_start = time.time()
         self.align_matrix = align_matrix(context, self.startlocation)
         draw_curve(self, context, self.align_matrix)
+        
+        if use_enter_edit_mode:
+            bpy.ops.object.mode_set(mode = 'EDIT')
+        
+        # restore pre operator state
+        bpy.context.preferences.edit.use_enter_edit_mode = use_enter_edit_mode
 
         #self.report({'INFO'},
                     #"Drawing Spiral Finished: %.4f sec" % (time.time() - time_start))
diff --git a/add_curve_extra_objects/add_curve_torus_knots.py b/add_curve_extra_objects/add_curve_torus_knots.py
index ea00bd2a..29c61011 100644
--- a/add_curve_extra_objects/add_curve_torus_knots.py
+++ b/add_curve_extra_objects/add_curve_torus_knots.py
@@ -45,7 +45,10 @@ from mathutils import (
         Vector,
         Matri

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list