diff options
-rw-r--r-- | curve_tools/Operators.py | 103 | ||||
-rw-r--r-- | curve_tools/__init__.py | 2 |
2 files changed, 99 insertions, 6 deletions
diff --git a/curve_tools/Operators.py b/curve_tools/Operators.py index 89f08f72..edf16ab1 100644 --- a/curve_tools/Operators.py +++ b/curve_tools/Operators.py @@ -620,8 +620,7 @@ class ConvertBezierToSurface(bpy.types.Operator): @classmethod def poll(cls, context): - return (context.object is not None and - context.object.type == 'CURVE') + return Util.Selected1OrMoreCurves() def execute(self, context): # main function @@ -687,8 +686,7 @@ class BezierPointsFillet(bpy.types.Operator): @classmethod def poll(cls, context): - return (context.object is not None and - context.object.type == 'CURVE') + return Util.Selected1OrMoreCurves() def execute(self, context): # main function @@ -800,8 +798,7 @@ class BezierDivide(bpy.types.Operator): @classmethod def poll(cls, context): - return (context.object is not None and - context.object.type == 'CURVE') + return Util.Selected1OrMoreCurves() def execute(self, context): # main function @@ -915,6 +912,99 @@ class CurveScaleReset(bpy.types.Operator): return {'FINISHED'} +# ------------------------------------------------------------ +# Split Operator + +class Split(bpy.types.Operator): + bl_idname = "curvetools.split" + bl_label = "Split" + bl_options = {'REGISTER', 'UNDO'} + + @classmethod + def poll(cls, context): + return Util.Selected1OrMoreCurves() + + def execute(self, context): + selected_Curves = Util.GetSelectedCurves() + + for curve in selected_Curves: + spline_points = [] + select_points = {} + bezier_spline_points = [] + select_bezier_points = {} + i_bp = 0 + i_p = 0 + for spline in curve.data.splines: + if spline.type == 'BEZIER': + points = {} + select_bezier_points[i_bp] = [len(spline.bezier_points)] + for i in range(len(spline.bezier_points)): + bezier_point = spline.bezier_points[i] + points[i]=[bezier_point.co[:], bezier_point.handle_left[:], bezier_point.handle_right[:]] + + if spline.bezier_points[i].select_control_point: + select_bezier_points[i_bp].append(i) + i_bp+=1 + bezier_spline_points.append(points) + else: + points = {} + select_points[i_p] = [len(spline.points)] + for i in range(len(spline.points)): + point = spline.points[i] + points[i]=[point.co[:], spline.type] + if spline.points[i].select: + select_points[i_p].append(i) + i_p+=1 + spline_points.append(points) + + curve.data.splines.clear() + + for key in select_bezier_points: + + num=0 + + if select_bezier_points[key][-1] == select_bezier_points[key][0]-1: + select_bezier_points[key].pop() + + for i in select_bezier_points[key][1:]+[select_bezier_points[key][0]-1]: + if i != 0: + spline = curve.data.splines.new('BEZIER') + spline.bezier_points.add(i-num) + + for j in range(num, i): + bezier_point = spline.bezier_points[j-num] + + bezier_point.co = bezier_spline_points[key][j][0] + bezier_point.handle_left = bezier_spline_points[key][j][1] + bezier_point.handle_right = bezier_spline_points[key][j][2] + bezier_point = spline.bezier_points[-1] + bezier_point.co = bezier_spline_points[key][i][0] + bezier_point.handle_left = bezier_spline_points[key][i][1] + bezier_point.handle_right = bezier_spline_points[key][i][2] + num=i + + for key in select_points: + + num=0 + + if select_points[key][-1] == select_points[key][0]-1: + select_points[key].pop() + + for i in select_points[key][1:]+[select_points[key][0]-1]: + if i != 0: + spline = curve.data.splines.new(spline_points[key][i][1]) + spline.points.add(i-num) + + for j in range(num, i): + point = spline.points[j-num] + + point.co = spline_points[key][j][0] + point = spline.points[-1] + point.co = spline_points[key][i][0] + num=i + + return {'FINISHED'} + operators = [ OperatorCurveInfo, OperatorCurveLength, @@ -934,4 +1024,5 @@ operators = [ BezierPointsFillet, BezierDivide, CurveScaleReset, + Split, ] diff --git a/curve_tools/__init__.py b/curve_tools/__init__.py index db56ff6a..e38f854e 100644 --- a/curve_tools/__init__.py +++ b/curve_tools/__init__.py @@ -375,6 +375,8 @@ class VIEW3D_PT_CurvePanel(Panel): row = col.row(align=True) row.operator("curve.bezier_cad_subdivide", text="Multi Subdivide") row = col.row(align=True) + row.operator("curvetools.split", text='Split by selected points') + row = col.row(align=True) row.operator("curve.add_toolpath_discretize_curve", text="Discretize Curve") row = col.row(align=True) row.operator("curve.bezier_cad_array", text="Array selected spline") |