It is possible to generate a curve in python through n number of points and the curve to be hooked to the points? Extrapolating I want to be able to generate curve through center of cubes curve that will stay hooked with the cubes so any update to the cubes will update the curve.


1 Answer 1

import bpy
from mathutils import Vector
cubes = [ob for ob in bpy.context.scene.objects if ob.name.startswith('Cube')]
spline = bpy.context.active_object
length = len(spline.data.splines[0].points)
for i in range(length):
    point = spline.data.splines[0].points[i]
    cube = cubes[i]
    point.select = True
    point.co = Vector((cube.location.x, cube.location.y, cube.location.z, 1))

It's a bit quick and dirty, so here are the preparations you need to do:

  1. The scripts selects the cubes by name, in alphabetical order. If any object in your scene starts with 'Cube' (e.g. Cube.001), it will be added to the cube array. There are more elegant ways to select a group of objects, but this was the simplest one.
  2. You need at least as many cubes as the spline has points.
  3. You need to select the curve and go into Edit Mode before running the script.

You must log in to answer this question.

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