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.
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.points) for i in range(length): bpy.ops.curve.select_all(action='DESELECT') point = spline.data.splines.points[i] cube = cubes[i] point.select = True point.co = Vector((cube.location.x, cube.location.y, cube.location.z, 1)) cube.select_set(True) bpy.ops.object.hook_add_selob(use_bone=False) cube.select_set(False)
It's a bit quick and dirty, so here are the preparations you need to do:
- 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.
- You need at least as many cubes as the spline has points.
- You need to select the curve and go into Edit Mode before running the script.