1
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ Is using Python a requirement or are you trying only to achieve some visual effect? $\endgroup$ – atomicbezierslinger Feb 22 '16 at 22:11
  • $\begingroup$ 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. $\endgroup$ – atomicbezierslinger Feb 22 '16 at 22:21
  • $\begingroup$ Yes, Python is requirement in my case because I want to do batch scripting with it. $\endgroup$ – MatX Feb 22 '16 at 22:59
  • $\begingroup$ blender.stackexchange.com/questions/47471/… Is this the same question? $\endgroup$ – atomicbezierslinger Feb 22 '16 at 23:57
  • $\begingroup$ 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? $\endgroup$ – atomicbezierslinger Feb 23 '16 at 1:19
3
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ You question needs to be changed to match the answer. $\endgroup$ – atomicbezierslinger Feb 23 '16 at 18:45
-1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – MatX Feb 22 '16 at 22:58
  • $\begingroup$ 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. $\endgroup$ – MatX Feb 23 '16 at 8:31
  • $\begingroup$ @MatX You should change your question and remove the above comments. $\endgroup$ – atomicbezierslinger Feb 23 '16 at 18:43

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.