# Hooking selected object to control point of Bezier curve via scripting

I'm trying to hook an object - namely a cube, which is a Mesh - to a specified control point of a Bezier curve - which is a Curve - by scripting. So I do the following and it doesn't work:

bpy.data.objects['Cube'].select = True # it has to be selected
bpy.data.objects['BezierCircle'].select = True # it has to be selected too
# and it has to be the active one as well
bpy.context.scene.objects.active = bpy.data.objects['BezierCircle'].splines[0].bezier_points[0]


It says that it doesn't find the 'splines' attribute. OK, so if I change it to a curve, like this:

bpy.data.objects['Cube'].select = True
bpy.data.objects['BezierCircle'].select = True
bpy.context.scene.objects.active = bpy.data.curves['BezierCircle'].splines[0].bezier_points[0]


then it says that it is expecting an Object, and not a BezierSplinePoint.

If it would be accepted, the following command should do the hooking:

bpy.ops.object.hook_add_selob(use_bone = False)


So that the Cube would be hooked to the control point I'm indexing.

Now what do you suggest I should do?

• Is using Python a requirement or are you trying only to achieve some visual effect? – atomicbezierslinger Feb 22 '16 at 22:11
• As a simplification do not think of a curve vertex as an object for the Python above. Think of items such as Mesh, Curve, Text and the Empty as objects. Armature can get a special treatment. Something that would appear in the outliner window. Do not consider the internal vertex as on object. – atomicbezierslinger Feb 22 '16 at 22:21
• Yes, Python is requirement in my case because I want to do batch scripting with it. – MatX Feb 22 '16 at 22:59
• blender.stackexchange.com/questions/47471/… Is this the same question? – atomicbezierslinger Feb 22 '16 at 23:57
• Is your question really something like this? I have some Python from a previous question and I need it to do something differently. Here is the different task [X]. How do I do this? Do you need to select a control point? How is that determined? – atomicbezierslinger Feb 23 '16 at 1:19

OK guys, I think I found the solution! Here: https://www.youtube.com/watch?v=ImWd1-FxhE4

In case the video becomes deleted in the future for some reason, here is the key to selecting the desired control point: (just an example)

bpy.data.curves['BezierCurve'].splines[0].bezier_points[0].select_control_point = True


So basically there is this boolean data member of the control points called select_control_point and you just have to set it to true.

• You question needs to be changed to match the answer. – atomicbezierslinger Feb 23 '16 at 18:45

I believe you can delete the troublesome statement.

The vertices selected are associated the object being edited. Then the other mesh, or empty is the controller. The operator will find the selected vertices. You do not need to set the active object again. Delete the statement.

Footnote.

The original question has changed in comments by the OP but the original question text remains.

• Yes, thank you I know how to do it like this, but I need to be able to script it because I don't want to click things a hundred times... I only asked the question for 1 specific thing, because then if I know how to do it, I can do it for 100 as well. – MatX Feb 22 '16 at 22:58
• The main problem is how to select a specific control point on the curve so that it becomes the active object, like when you right-click it. – MatX Feb 23 '16 at 8:31
• @MatX You should change your question and remove the above comments. – atomicbezierslinger Feb 23 '16 at 18:43