2
$\begingroup$

Version: Blender 2.81

Using the Python API, I want to create a default path and then add individual points to it.

The code below does this. Except that it extends both the beginning and the end of the curve.

import bpy

# kill everything

bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False, confirm=False)

# create curve

bpy.ops.curve.primitive_nurbs_path_add(radius=1, enter_editmode=False, location=(0, 0, 0))

# switch to edit mode

bpy.ops.object.editmode_toggle()

# add new point for curve

bpy.ops.curve.extrude_move(CURVE_OT_extrude={"mode":'TRANSLATION'}, 
    TRANSFORM_OT_translate={"value":(0, 2, 0)}
    )

In the viewpoint, I can extend the END of the curve by toggling edit mode, and then doing this: double-clicking the last point, and pressing E.

I can't figure out how to use python to select this last point.

$\endgroup$

1 Answer 1

2
$\begingroup$

try this (I am on Blender 2.81a):

import bpy

# kill everything
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False, confirm=False)

# create curve
bpy.ops.curve.primitive_nurbs_path_add(radius=1, enter_editmode=False)
obj = bpy.context.object

# De-select all points
for pn in obj.data.splines[0].points:
    pn.select = False

# Select the last point
pn = obj.data.splines[0].points
end_point_idx = (len(obj.data.splines[0].points) - 1)
pn[end_point_idx].select = True

bpy.ops.object.mode_set(mode='EDIT') # Edit mode

bpy.ops.curve.extrude_move(CURVE_OT_extrude={"mode":'TRANSLATION'},
TRANSFORM_OT_translate={"value":(0, 2, 0)})

bpy.ops.object.mode_set(mode='OBJECT') # Object mode

(Make sure you are in object mode when you run it)

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.