1
$\begingroup$

I am trying to write a script for modeling certain forms and this part is really challenging for me as a beginner.

I'd like python to tell me the distance from the Active Vertex to the Farthest Selected Vertex. Furthermore I'd like the distance to be "flattened" on one Axis, in this example Z. Meaning, I'd like python to find the distance between the Active and the Farthest Vertex within my selection, but then disregard the height.

enter image description here

$\endgroup$
2
$\begingroup$

Vectors

Test script run in edit mode, with selected verts and a vertex as active selection.

Sort the active verts by distance from active vert. Select the last, ie the furthest vert, from active vert. Use only the xy components of each to calculate the projected length required.

import bpy
import bmesh

context = bpy.context
ob = context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)
# assume have active vert
av = bm.select_history.active
verts = [v for v in bm.verts if v.select]
#verts.remove(v)
verts.sort(key=lambda v:(av.co - v.co).length)
# furthest vert
fv = verts[-1]
# distance between verts
print((fv.co - av.co).length)
# distance disregarding local z component
print((fv.co.xy - av.co.xy).length)

Result when run on default cube, all verts selected

3.4641016151377544  # 2 * sqrt(3)
2.8284271247461903  # 2 * sqrt(2)
$\endgroup$

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.