Snap objects to vertices

This is a very simple script to snap all objects to the last selected object. In the example below, the cubes were selected first then the icoSphere. Then, the script was run:

Here is the python script:

import bpy
from bpy import context

allobjects = bpy.context.selected_objects
allobjectslengthminusone = (len(allobjects)-1)
lastobject = allobjects[allobjectslengthminusone]

obj = lastobject
mesh = obj.data
vectorlist = []

for vert in mesh.vertices:
 vectorlist.append(obj.matrix_world * vert.co)

for i in range(allobjectslengthminusone):
 allobjects[i].location = vectorlist[i]

Leave a Reply

Your email address will not be published. Required fields are marked *