3
$\begingroup$

One issue I'm having is specifically with the bpy.ops.object.hook_assign() method on a currently selected vertex.

mod_name = "Hook" + str(vertex_idx)
obj.modifiers.new(mod_name, type='HOOK')
obj.modifiers[mod_name].object = other_obj

bpy.ops.object.hook_assign(modifier=mod_name)

I am trying to tell blender which modifier in the stack to apply the operation to, but get the following message when I do it from the python console:

TypeError: Converting py args to operator properties: enum "Hook0" not found in ()

Has anyone had any experience with using hook_assign() at all? Sadly this functionality of hooking an object to another object's vertex is exactly what I need, and it isn't supported directly in the HookModifier object API.

$\endgroup$
3
$\begingroup$

Tested with the default scene in editmode with a single vertex selected.

 import bpy
 vertex_idx = 0
 obj = bpy.context.object
 other_obj = [o for o in bpy.context.scene.objects if o != obj][0]


 mod_name = "Hook" + str(vertex_idx)
 obj.modifiers.new(mod_name, type='HOOK')
 obj.modifiers[mod_name].object = other_obj

 bpy.ops.object.hook_assign(modifier=mod_name)

This worked for me, however this code shows a common mistake,

That is that you're assuming Blender is giving you the name you ask for, There is no guarantee you get the name you ask for when creating new data. (it could be shortened or have a .001 added if the name exists already).

So best use the modifier name directly.

eg:

 mod = obj.modifiers.new("Hook" + str(vertex_idx), type='HOOK')
 mod.object = other_obj

 bpy.ops.object.hook_assign(modifier=mod.name)
$\endgroup$
1
  • $\begingroup$ Yep, this was exactly the problem. Once again I am duped by cryptic/wrong error messages from the compiler. Thanks for the help! $\endgroup$
    – havocheavy
    Apr 10 '14 at 14:33

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.