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..

  • $\begingroup$ You have to copy the values, I guess you are getting pointers instead try with. .copy() $\endgroup$
    – Chebhou
    Jan 14 '16 at 20:11
  • 1
    $\begingroup$ Also if you post the code you have so far it would be easier $\endgroup$
    – 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()


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


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


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

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

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.