{"id":12146,"date":"2026-04-17T13:06:31","date_gmt":"2026-04-17T18:06:31","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=12146"},"modified":"2026-04-17T13:06:32","modified_gmt":"2026-04-17T18:06:32","slug":"blender-script-distance-between-two-points","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=12146","title":{"rendered":"Blender Script: Distance Between Two Points"},"content":{"rendered":"\n<p>We were having a lot of trouble using the measure tool in Blender &#8212; after discovering that you can hold the Ctrl key and &#8220;snap&#8221; your selection to a vertex, it actually worked in the way we wanted it to. But, before that discovery, my thought was to manually select two vertices and use a Python script to measure the distance between those points. That is &#8220;blender units&#8221; &#8230; and the metric or imperial units would be more meaningful. So I converted based on the scene configuration. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport bpy\nimport bmesh\n\n\ndef format_metric(meters: float) -&gt; str:\n    a = abs(meters)\n\n    if a &gt;= 1.0:\n        return f&quot;{meters:.6f} m&quot;\n    elif a &gt;= 0.01:\n        return f&quot;{meters * 100.0:.3f} cm&quot;\n    else:\n        return f&quot;{meters * 1000.0:.3f} mm&quot;\n\n\ndef format_imperial(meters: float) -&gt; str:\n    total_inches = meters \/ 0.0254\n    sign = &quot;-&quot; if total_inches &lt; 0 else &quot;&quot;\n    total_inches = abs(total_inches)\n\n    feet = int(total_inches \/\/ 12)\n    inches = total_inches - (feet * 12)\n\n    if feet &gt; 0:\n        return f&quot;{sign}{feet} ft {inches:.3f} in&quot;\n    else:\n        return f&quot;{sign}{total_inches:.3f} in&quot;\n\n\ndef measure_selected_vertices():\n    ctx = bpy.context\n    obj = ctx.edit_object\n\n    if obj is None or obj.type != &#039;MESH&#039;:\n        raise RuntimeError(&quot;Go into Edit Mode on a mesh and select exactly 2 vertices.&quot;)\n\n    bm = bmesh.from_edit_mesh(obj.data)\n    selected_verts = &#x5B;v for v in bm.verts if v.select]\n\n    if len(selected_verts) != 2:\n        raise RuntimeError(f&quot;Expected exactly 2 selected vertices, found {len(selected_verts)}.&quot;)\n\n    v1, v2 = selected_verts\n\n    # Convert local vertex coordinates to world-space coordinates\n    p1 = obj.matrix_world @ v1.co\n    p2 = obj.matrix_world @ v2.co\n\n    # Raw world-space distance in Blender units\n    raw_distance = (p2 - p1).length\n\n    scene = ctx.scene\n    units = scene.unit_settings\n    scale_length = units.scale_length if units.scale_length != 0 else 1.0\n\n    # Convert Blender units to meters according to the scene unit scale\n    distance_meters = raw_distance * scale_length\n\n    print(&quot;\\n----- Vertex Distance -----&quot;)\n    print(f&quot;Object: {obj.name}&quot;)\n    print(f&quot;Raw distance (Blender units): {raw_distance:.6f}&quot;)\n    print(f&quot;Scene unit system: {units.system}&quot;)\n    print(f&quot;Scene unit scale: {scale_length}&quot;)\n\n    if units.system == &#039;METRIC&#039;:\n        print(f&quot;Formatted distance: {format_metric(distance_meters)}&quot;)\n\n    elif units.system == &#039;IMPERIAL&#039;:\n        print(f&quot;Formatted distance: {format_imperial(distance_meters)}&quot;)\n\n    else:\n        print(&quot;Formatted distance: Scene unit system is &#039;NONE&#039;&quot;)\n        print(f&quot;Interpreted using current unit scale: {format_metric(distance_meters)}&quot;)\n\n\nmeasure_selected_vertices()\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>We were having a lot of trouble using the measure tool in Blender &#8212; after discovering that you can hold the Ctrl key and &#8220;snap&#8221; your selection to a vertex, it actually worked in the way we wanted it to. But, before that discovery, my thought was to manually select two vertices and use a &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2163],"tags":[2158,2182,2177,664],"class_list":["post-12146","post","type-post","status-publish","format-standard","hentry","category-blender-3d-printing","tag-blender","tag-blender-api","tag-bpy","tag-python"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/12146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12146"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/12146\/revisions"}],"predecessor-version":[{"id":12147,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/12146\/revisions\/12147"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}