9
$\begingroup$

I try to use points from an import as a spline to make curves as paths to follow for an animation.

These curves share some points at the ends and beginning when I import them via Python.

For example
s1: A-a-b-B s2: C--D s3: B-c-C s4: D-d-E

which in the viewport look like A-a-b-B-c-C--D-d-E

I want to join them together, so that I'll have one single spline s5: A-a-b-B-c-C--D-d-E

I could use CtrlJ to join them, but they are still not merged at their shared points, which makes the rest of the spline not used for the following. If I join them it looks like: s1: A-a-b-BB-c-CC--DD-d-E

Also, another part of the problem is that the order of the splines from the import is not given, that s1 and s2 may not have shared nodes, and are only connected to each other via others like s3 and s4.

Is there a way to merge them? via commands or scripting

$\endgroup$

2 Answers 2

7
$\begingroup$

Select the two ends you want to join in editmode and press F. If the shared ends are in the same place, you might want to delete one of them before connecting the curves.

$\endgroup$
4
  • $\begingroup$ unfortunatly that does not work, gives "Cannot make segment", but thanks anyway $\endgroup$ Aug 28, 2013 at 6:39
  • $\begingroup$ explain your situation as precisely as possible. Because it works very well here. What exactly do you do, what type of curve is it, how many have you selected, etc. The easiest way is to upload a small! blend at pasteall.org. Then I can analyze $\endgroup$ Aug 28, 2013 at 16:21
  • $\begingroup$ i guess its because it is not a beziercurve and therefor it fails: "cd = bpy.data.curves.new(name=curvename, type='CURVE')" and "cd.splines.new('POLY')" $\endgroup$ Aug 29, 2013 at 9:00
  • $\begingroup$ joining two splines within a curve requires both splines to be the same type. If one is Bezier and the other is Polyline, select the polyline and use the Set Spline Type button in the Tools/Curve Tools section of the t-panel to turn it into a bezier. $\endgroup$
    – Mutant Bob
    Jan 4, 2016 at 19:30
3
$\begingroup$

Natively the only way to join splines is using Make Segment, which is a bit of a hassle for your use case as you'll need to manually change handle types, snap handles and remove points.

The following adds a Merge operator that attempts to handle all that for you:

import bpy

class OBJECT_OT_CurveMerge(bpy.types.Operator):
    """Merge two bezier curve points"""
    bl_idname = "curve.merge"
    bl_label = "Merge"
    bl_options = {"REGISTER", "UNDO"}

    @classmethod
    def poll(cls, context):
        return context.mode == "EDIT_CURVE"

    def execute(self, context):
        try:
            bpy.ops.curve.make_segment()
        except RuntimeError:
            pass # Already joined.

        spline = bpy.context.object.data.splines.active
        selected = [p for p in spline.bezier_points if p.select_control_point]

        if len(selected) != 2:
            self.report({"WARNING", "ERROR"}, "Cannot merge points")
            return {"CANCELLED"}

        center = selected[0].co.lerp(selected[1].co, 0.5)
        selected[0].co = selected[1].co = center

        selected[0].handle_left_type = selected[1].handle_left_type = \
        selected[0].handle_right_type = selected[1].handle_right_type = "FREE"
        if spline.use_cyclic_u:
            selected[0].handle_left = selected[1].handle_left
        else:
            selected[0].handle_right = selected[1].handle_right

        bpy.ops.curve.select_all(action="DESELECT")
        selected[1].select_control_point = True
        bpy.ops.curve.delete(type="SELECTED")
        return {"FINISHED"}

def register():
    bpy.utils.register_class(OBJECT_OT_CurveMerge)

register()

With the above loaded:

  1. Join the curves Ctrl+J
  2. Select points s1:B and s2:B Space,Merge
    • Repeat for the rest of the points you wish to merge.
$\endgroup$
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .