3
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ You have to copy the values, I guess you are getting pointers instead try with. .copy() $\endgroup$
    – Chebhou
    Commented Jan 14, 2016 at 20:11
  • 1
    $\begingroup$ Also if you post the code you have so far it would be easier $\endgroup$
    – Chebhou
    Commented Jan 14, 2016 at 20:12

1 Answer 1

5
$\begingroup$

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)
$\endgroup$
1
  • $\begingroup$ thank you for your time! your code saved my life (at least many hours). $\endgroup$
    – e-proxy
    Commented Jan 14, 2016 at 21:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .