Skip to content
Snippets Groups Projects
Commit d605104b authored by Spivak Vladimir (cwolf3d)'s avatar Spivak Vladimir (cwolf3d)
Browse files

Add Curve: Extra Objects: addon fix when enabled...

Add Curve: Extra Objects: addon fix when enabled bpy.context.preferences.edit.use_enter_edit_mode = True
parent 1a1ba20a
No related branches found
Tags
No related merge requests found
......@@ -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):
......
......@@ -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'}
......
......@@ -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'}
......
......@@ -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'}
......
......@@ -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'}
......
......@@ -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))
......
......@@ -45,7 +45,10 @@ from mathutils import (
Vector,
Matrix,
)
from bpy_extras.object_utils import AddObjectHelper
from bpy_extras.object_utils import (
AddObjectHelper,
object_data_add
)
from random import random
from bpy.types import Operator
......@@ -264,11 +267,8 @@ def create_torus_knot(self, context):
curve_data.extrude = self.geo_extrude
curve_data.offset = self.geo_offset
new_obj = bpy.data.objects.new(aName, curve_data)
# set object in the scene
scene = bpy.context.scene
scene.collection.objects.link(new_obj) # place in active scene
new_obj = object_data_add(context, curve_data) # place in active scene
bpy.ops.object.select_all(action='DESELECT')
new_obj.select_set(True) # set as selected
bpy.context.view_layer.objects.active = new_obj
......@@ -675,11 +675,13 @@ class torus_knot_plus(Operator, AddObjectHelper):
@classmethod
def poll(cls, context):
if context.mode != "OBJECT":
return False
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
if self.mode == 'EXT_INT':
# adjust the equivalent radii pair : (R,r) <=> (eR,iR)
self.torus_R = (self.torus_eR + self.torus_iR) * 0.5
......@@ -711,6 +713,12 @@ class torus_knot_plus(Operator, AddObjectHelper):
# create the curve
create_torus_knot(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'}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment