I want to add a segment between two given points, I don't want to add a new point, just connecting the two points. Does someone know how to do this with the low level api?
This is a bit complicated, so I'm just going to give you one example and let you work out the details for other situations.
Here is a Bezier Curve to which I've added a disconnected control point:
If I select the object containing this Bezier curve and make it the active object, then I can get to the curve in Edit mode by accessing it's Curve structure, through the active object's data field. To accomplish your goal I need to access the Curve's splines:
import bpy curve = bpy.context.active_object curve.data.splines.bezier_points.select_control_point = False curve.data.splines.bezier_points.select_control_point = True curve.data.splines.bezier_points.select_control_point = True
Here is the first complexity: This is a Bezier Curve, so to get to its control points, I need to use the
Bezier_points field. How to get to the equivalent data for a NURBS curve is left as an exercise. However the field is [
But there's a second complexity. This curve has two splines. The original curve is in the 0th spline, but the new control point is in the 1st spline. Notice the indices used for the references above.
To add a segment between two control points, I have to deselect all of the other control points, and select the two relevant points. Because there are only three points here, I do this with each point separately. Running the above code segment produces
Notice that I did not deselect the control handles. Only the control points are relevant for a Bezier Curve.
Finally we come to the code that adds the segment between the two selected handles:
This is the same code you would use even for a NURBS curve.
$\begingroup$ thanks, I think using the make_segment op is the only solution $\endgroup$ Mar 11, 2022 at 13:10
$\begingroup$ you're welcome. Curves can be a bit messy to deal with. $\endgroup$ Mar 11, 2022 at 14:45