do you know how I can iterate through all the vertices of a mesh, and add a new Empty object as a hook to them via using a script? Like you would do by clicking on them in Edit Mode and then pressing Ctrl+H.

I'm trying to achieve this by the following code unsuccessfully so far:

# I import the bpy and do various things here which work, but the below one doesn't

current_obj = bpy.context.object

for vert in current_obj.data.vertices:          

Thank you for the support in advance!

  • $\begingroup$ bpy.ops.object.hook_add_newob() $\endgroup$ – yhoyo Feb 22 '16 at 15:43
  • $\begingroup$ Yes I tried this already and it also doesn't work. I can't even read the error message just that "Phython script fail, look in the console" - but there is nothing in the console... $\endgroup$ – MatX Feb 22 '16 at 15:58

Try this:

import bpy, bmesh

# Create a persistent reference to current object
current_obj = bpy.data.objects[ bpy.context.object.name ]

bpy.ops.object.mode_set( mode = 'EDIT' ) # Go to edit mode

bm = bmesh.from_edit_mesh( current_obj.data )

for i in range( len( bm.verts ) ):
    bpy.context.scene.objects.active = current_obj
    bpy.ops.mesh.select_all( action = 'DESELECT' ) # Deselect all vertices
    bm = bmesh.from_edit_mesh( current_obj.data )
    v  = bm.verts[i]
    v.select = True
    bm.select_flush( True )

bpy.ops.object.mode_set( mode = 'OBJECT' )     # Back to object mode
| improve this answer | |

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.