# move a vertex to the position of another vertex (different object) in python?

i basically need this: How do I snap one vertex to the position of another vertex in a different object? to be done by a python script.

i've managed to move a single vertex along one axis so far.. my problem is, that i struggle with the orientation options in blender. i would like to select vertices from object2 via index (no problems so far) and copy their location and save these values to the selected vertices of object1. why is it, that for example bpy.data.meshes['Cube'].vertices[0].co doesn't give you coordinates from 0,0,0? sorry for my noobishness..

• You have to copy the values, I guess you are getting pointers instead try with. .copy() – Chebhou Jan 14 '16 at 20:11
• Also if you post the code you have so far it would be easier – Chebhou Jan 14 '16 at 20:12

I wrote this example script for you. Mind the comments.

import bpy
import bmesh

# Get the coordinates of the first vertices of 'Plane' object
firstObjData = bpy.context.scene.objects['Plane'].data
bm1 = bmesh.new()
bm1.from_mesh(firstObjData)

bm1.verts.ensure_lookup_table()

# Convert local coorinates to world coordinates before assignment
vertCoordinates = bpy.data.objects['Plane'].matrix_world * bm1.verts[0].co.xyz

print(vertCoordinates)

# Set the coordinates of the first vertices of 'Cube' object
secondObjData = bpy.context.scene.objects['Cube'].data
bm2 = bmesh.new()
bm2.from_mesh(secondObjData)

bm2.verts.ensure_lookup_table()

# Convert world coorinates to local coordinates before assignment
bm2.verts[0].co.xyz = bpy.data.objects['Cube'].matrix_world.inverted() * vertCoordinates

bm2.to_mesh(secondObjData)

• thank you for your time! your code saved my life (at least many hours). – e-proxy Jan 14 '16 at 21:43