1

I am looking at how to use python and make a code that automatically detects an empty on a vertex point and hooks them together. How can I do this and add it to the code I already have?

import bpy
from bpy import context
i = 0
c = 8

obj = context.active_object while not i == c: v = obj.data.vertices[i] co_final = obj.matrix_world @ v.co obj_empty = bpy.data.objects.new("Point", None) context.collection.objects.link(obj_empty) obj_empty.location = v.co obj_empty.parent = obj
i += 1

1 Answers1

1

Set parent type to vertex.

Going by code in question it appears you wish to set each vertex as a parent of an empty.

In this case moving the vertex moves the empty.

Snaffled code from this answer

Notice that there is no requirement to set the empty location to the vertex, rather let the parenting take care of this. Having zero local translation from the location of the parent. Using the UI confuses the issue somewhat as it sets the parent inverse

import bpy
from bpy import context

ob = context.object coll = context.collection

for v in ob.data.vertices: mt = bpy.data.objects.new( f"Vert{v.index}", None, ) mt.empty_display_type = 'CIRCLE' mt.empty_display_size = 0.2 mt.parent = ob mt.parent_type = 'VERTEX' mt.parent_vertices = [v.index] * 3 coll.objects.link(mt)

Re "hook" generally infers hooking a vertex to the empty such that moving the empty moves the vert.

How to iterate through mesh vertices and add hooks using script

batFINGER
  • 84,216
  • 10
  • 108
  • 233