0
$\begingroup$

I have following little script, fetch the points from the bezier and add a Null object at each point.

from bpy import context, data, ops


bez_curve = context.active_object
bez_points = bez_curve.data.splines[0].bezier_points

for p in bez_points:
    new_obj = data.objects.new('spline_point', None) 
    new_obj.location = p.co
    context.scene.collection.objects.link(new_obj)

But the Nulls I create at each point is placed in what looks like random locations. Total of 4 points added to the Bezier. I have obviously missed something here!

enter image description here

$\endgroup$
0

1 Answer 1

1
$\begingroup$

Curve coordinates p.co are local coordinates.

Use the curve world matrix to transform them to world coordinates:

from bpy import context, data, ops

bez_curve = context.active_object
bez_points = bez_curve.data.splines[0].bezier_points
world_matrix = bez_curve.matrix_world # Get the matrix

for p in bez_points:
    new_obj = data.objects.new('spline_point', None) 
    new_obj.location = world_matrix @ p.co # Use it to transform coordinates in world coordinates
    context.scene.collection.objects.link(new_obj)
$\endgroup$
1
  • $\begingroup$ Was not even close to resolving this one on my own! This should really be pointed out in the documentation more clearly. $\endgroup$
    – StefanE
    Commented Sep 26, 2020 at 9:50

You must log in to answer this question.

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