def METHOD_NAME(obj):
    with butil.ViewportMode(obj, 'EDIT'):
        bpy.ops.mesh.select_all(action='SELECT')
        bpy.ops.mesh.region_to_loop()
    vg = obj.vertex_groups.new(name='distance')
    with butil.ViewportMode(obj, 'EDIT'):
        bm = bmesh.from_edit_mesh(obj.data)
        bm.verts.ensure_lookup_table()
        distance = np.full(len(obj.data.vertices), -100.)
        queue = set(v.index for v in bm.verts if v.select)
        d = 0
        while True:
            distance[list(queue)] = d
            next_queue = set()
            for i in queue:
                v = bm.verts[i]
                for e in v.link_edges:
                    next_queue.add(e.other_vert(v).index)
            queue = set(i for i in next_queue if distance[i] < 0)
            if not queue:
                break
            d += 1
    distance[distance < 0] = 0
    distance /= max(d, 1)
    for i, d in enumerate(distance):
        vg.add([i], d, 'REPLACE')
    return distance