Moving the end of a curve object

Hey,

I’m planning on using a Curve (specifically the Path primitive) in combination with the Curve Guide field to guide a particle stream from one object to another. I can create and position the Path, but have been unable to move the endpoint to where I want it to go.

In Blender itself this is easy - right-click on the end vertex and drag it to wherever I want it. But how would I ‘get’ that vertex in Python, if I wanted to? Or is there a better way to move the endpoint of my path? Or even a better way to guide the particle stream?

Currently I’ve been using a combination of scale, rotate_euler, and location to get the Path to connect the two objects - but this frustrating and difficult. I think there must be a simpler way to do this, but so far have been unable to find one.

Thanks to anyone who can help.

here is a basic snippet to start with, it moves last point of first spline in path to cursor location


import bpy
cur = bpy.context.scene.cursor_location
path = bpy.data.objects.get('NurbsPath')
loc = cur - path.location
path.data.splines[0].points[-1].co = loc.to_4d()

if you rotate or scale the path then you need to change it a bit