I am surprise there isn’t a script for this yet. I did do a search but didn’t really get anything that matched.
I need a simple script. I have 3 vertices in this example but in reality I’ll have many vertices selected. I select the first 2 vertices and then select the last vertex. I want to move the first 2 vertices to the last selected vertex Z position.
A second variation of this script I need is the same requirements, but not just Z but also X position.
Thank you it works! I’m going to study it and see how it works I wish there was more video tutorials for artist on bmesh. Hell I would even pay for such a tutorial!
Edit: A caveat, this is more related to the nature of selections in Blender than the script. I am using lasso selection by default, for this script to work you have to click on the vertices, lassoing the vertices will cause the script to not work.
Sometimes I have many vertices I lasso select first, then even if I click and select the last vert(active vertex(maybe it’s not consider a active selection?)), the script won’t work. Not a big deal, just something people need to be aware of. I guess it’s more of a Blender thing I am not used to coming from Modo.
In that case, try this ammended script. It should always work as long as there is an active vert. However, it will be slower as the mesh gets larger.
import bpy
import bmesh
def vert_selected_to_active(bm, axis):
av = bm.select_history.active
if(not isinstance(av, bmesh.types.BMVert)):
return
selected_verts = [v for v in bm.verts if v.select]
for v in selected_verts:
match axis:
case 'x':
v.co.x = av.co.x
case 'y':
v.co.y = av.co.y
case 'z':
v.co.z = av.co.z
bmesh.update_edit_mesh(mesh)
object = bpy.context.object
mesh = object.data
bm = bmesh.from_edit_mesh(mesh)
vert_selected_to_active(bm, 'z')