1
$\begingroup$

I'm using a Bezier curve to generate a shape. Once I'm happy with the shape I process it with a script I wrote. Among other things it adds 2 empty objects: one at the start of the curve, one at the end of the curve.

I can't figure out how to rotate the empty objects so that they point in the same way the curve is pointing. Or how to align the empty's Y axis to the end point normal?

I access the end point data via curve.data.splines.active.bezier_points[pointId] but I couldn't find a way to get rotation or normal information.

Orientation that I'm trying to copy from curve end point to empty axis orientation.

Orientation I'm trying to copy

End result I'm trying to achieve: the empty's Y axis is aligned with the direction of the last curve point.

End result I'm trying to achieve

$\endgroup$

1 Answer 1

2
$\begingroup$

Use the follow path constraint

When it comes to putting an object at either end of a curve, the follow path constraint, with fixed location, follow curve. An offset factor of 0 is one end, 1 the other.

enter image description here

import bpy

context = bpy.context
bez = context.object

bpy.ops.object.empty_add(location=(0, 0, 0))
mt1 = context.object
fpc = mt1.constraints.new(type='FOLLOW_PATH')
fpc.target = bez
fpc.use_curve_follow = True
fpc.use_fixed_location = True
# dupe it
bpy.ops.object.duplicate()
mt2 = context.object
mt2.constraints[0].offset_factor = 1
$\endgroup$
1
  • 1
    $\begingroup$ Wow, that was much simpler than expected. Thank you very much! $\endgroup$
    – Virgiliu
    Jan 23, 2019 at 7:15

You must log in to answer this question.

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