Getting the last vertex in a line created from extruded a vertice

Hi I have a line created from extruded vertices and I try to select the last vertice in the line programmatically. any help would be appreciated.

Depending on what data you want from the vertex the following should help you.
edited to show access to different curve type point data.

import bpy

ob = bpy.context.object
if ob.type == 'MESH':
    # list of verts
    all_verts = ob.data.vertices
    # single vert still in list
    last_vert = all_verts[-1:]
    # single vert no list
    last_vert = all_verts[-1:][0]
    # coordinates
    last_vert.co
if ob.type == 'CURVE':
    # a single curve object can hold multiple curves
    # we will focus on 1st curve
    spline = ob.data.splines[0]
    if spline.type == 'BEZIER':
        # points are stored slightly differently in different curve types
        points = spline.bezier_points
        last_vert = points[-1:][0]
    if spline.type == 'POLY':
        points = spline.points
        last_vert = points[-1:][0]

print(last_vert.co)
1 Like

Possible solution.

import bpy

# mesh active
obj = bpy.context.active_object.name

# l_all = list with all vertices of the mesh
l_all = bpy.data.meshes[obj].vertices

# select the last vertex
bpy.ops.object.mode_set(mode='OBJECT')
l_all[-1].select = True

# Move l_all[-1]
bpy.ops.object.mode_set(mode='OBJECT')
l_all[-1].co.x += 0.1