0
$\begingroup$

I have a bezier already drawn and positioned, the ends coincide with 2 distinct objects. Suppose it is cube1 and cube2, the objects are already in the scene, so I would like to link the points of the bezier (2 vertices only) first cube1 and then cube2

import bpy

cube1= bpy.data.objects['Cube1']
cube2= bpy.data.objects['Cube2']
bezier = bpy.data.objects['BezierCurve']

The example is to point out that the objects are already drawn in the correct position of the scene, I don't have to change anything, I just have to connect the bezier to these 2 objects

$\endgroup$
1
$\begingroup$

That can be something like this:

import bpy

cube1= bpy.data.objects['Cube1']
cube2= bpy.data.objects['Cube2']
bezier = bpy.data.objects['BezierCurve']

hook = bezier.modifiers.new( name = "Hook-" + cube1.name, type = 'HOOK' )
hook.object = cube1
hook.vertex_indices_set( [0, 1, 2] )

hook = bezier.modifiers.new( name = "Hook-" + cube2.name, type = 'HOOK' )
hook.object = cube2
hook.vertex_indices_set( [3, 4, 5] )

The tricky part is you have to indicate each element of the control points you want to hook. So the hook vertex indices are triplets.

I don't think you can hook control point handles individually, but that may depend of the curve type or the control points mode and have not tested all possibilities.

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Thanks Lemon, it does exactly what I was asking, it wasn't very intuitive to me, now it's clear to my brain $\endgroup$ – Pastrokkio Sep 1 '19 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.