0
$\begingroup$

I`m trying to snap the ends of a curve, to two points in space. However, I can't get past the fact that It requires worldspace input of a matrix instead of a vector. I've tried to convert worldspace to local, and backwards but its not my strongpoint.

Any ideas are more then welcome. Thank you!

import bpy
from bpy import context, data, ops
from mathutils import Euler, Matrix, Quaternion, Vector


# Create bezier path.
ops.curve.primitive_nurbs_path_add(enter_editmode=True)
#ops.curve.subdivide(number_cuts=0)
ops.transform.resize(value=(2.0, 2.0, 3.5))
ops.object.mode_set(mode='OBJECT')
curve = context.active_object
curve.name = 'line'


# snap one end of curve to A other to B
location_a = (1,1,0) # (XYZ)
location_b = (2,2,0) # (XYZ)


curve.data.splines[0].points[0].co = Vector(location_a)
# error ->   
# Line 20 -> ValueError: bpy_struct: item.attr = val: sequences of dimension 0 should contain 4 items, not 3
```
$\endgroup$
3
  • $\begingroup$ Have marked this as a dupe.. . IMO The issue here is the 4th dimension of the nurbs curve is twist or radius can't remember, anyway as with all data coordinates these are in local coordinates. For most cases simply tack a 1 on as 4th coordinate. If you feel they don't answer your question, please inform and will re-open and answer or someone else using methods shown in dupe links above. $\endgroup$ – batFINGER Jul 12 '20 at 14:35
  • $\begingroup$ Or as @RayMairlot oft links to, whats known as the XY Problem $\endgroup$ – batFINGER Jul 12 '20 at 15:05
  • $\begingroup$ Perfect answer, very helpful, thank you! I hadn't realised the 4th dimension was something else. I had misdiagnosed it as some sort of matrix, but it wasnt. Thank you! $\endgroup$ – Henk Kok Jul 12 '20 at 15:58