# How to get vertex position and connected vertices?

**URL:** <https://blenderartists.org/t/how-to-get-vertex-position-and-connected-vertices/1185279>\
**Category:** Python Support\
**Created:** [October 12, 2019, 11:41am UTC](https://blenderartists.org/t/how-to-get-vertex-position-and-connected-vertices/1185279 "2019-10-12T11:41:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josip\_Kladaric](https://blenderartists.org/user_avatar/blenderartists.org/josip_kladaric/32/948953_2.png) [@Josip\_Kladaric](https://blenderartists.org/u/Josip_Kladaric)\
**Post date:** [October 12, 2019, 11:41am UTC](https://blenderartists.org/t/how-to-get-vertex-position-and-connected-vertices/1185279/1 "2019-10-12T11:41:23Z")

</div>

Hi, I’m new to Blenders bpy but I am familiar with Python.  
Once I have selected a mesh and saved a list of its vertices, I can select a single one from the list and process it. The way I want to process it requires me to get its position (local or global) and a list of connected vertices, how can I do that?

Thanks!

---

<div class="post-metadata">

**Author:** ![Secrop](https://blenderartists.org/user_avatar/blenderartists.org/secrop/32/20093_2.png) [@Secrop](https://blenderartists.org/u/Secrop)\
**Post date:** [October 12, 2019, 12:05pm UTC](https://blenderartists.org/t/how-to-get-vertex-position-and-connected-vertices/1185279/2 "2019-10-12T12:05:41Z")

</div>

Have you tried to use [bmesh](https://docs.blender.org/api/current/bmesh.html)?

```auto
import bmesh

mesh = bpy.context.view_layer.objects.active.data # object must be a mesh and in EditMode

bm = bmesh.from_edit_mesh(mesh)
for vert in bm.verts:
    vl=[]
    for l in vert.link_edges:
        vl.append(l.other_vert(vert).index)
    print("Vertex[", vert.index, "]:")
    print("\tco: ", vert.co)
    print("\tlinks: ", vl)
```

---

<div class="post-metadata">

**Author:** ![Josip\_Kladaric](https://blenderartists.org/user_avatar/blenderartists.org/josip_kladaric/32/948953_2.png) [@Josip\_Kladaric](https://blenderartists.org/u/Josip_Kladaric)\
**Post date:** [October 12, 2019, 12:20pm UTC](https://blenderartists.org/t/how-to-get-vertex-position-and-connected-vertices/1185279/3 "2019-10-12T12:20:22Z")

</div>

Didn’t even know about it, thank you very much.

---

<div class="post-metadata">

**Author:** ![ManBlender](https://blenderartists.org/user_avatar/blenderartists.org/manblender/32/811852_2.png) [@ManBlender](https://blenderartists.org/u/ManBlender)\
**Post date:** [April 28, 2024, 10:49am UTC](https://blenderartists.org/t/how-to-get-vertex-position-and-connected-vertices/1185279/4 "2024-04-28T10:49:21Z")

</div>

Why this not working for me? No any print… exist typical box, mesh.

```auto
import bpy
import bmesh

# Function to print vertex positions for each object
def print_vertex_positions():
    # Table header
    print("No.; Name; Location x; Location y; Location z;")

    # Variable to count vertices
    count = 1

    # Iterate through all objects in the scene
    for obj in bpy.data.objects:
        print("Object:", obj.name, "Type:", obj.type)
        # Check if the object is of type 'MESH'
        if obj.type == 'MESH':
            print("Processing mesh object:", obj.name)
            # Access the mesh data
            mesh = obj.data
            print("Mesh data:", mesh)
            # Create a new bmesh from the mesh data
            bm = bmesh.new()
            bm.from_mesh(mesh)
            print("BMesh created")

            # Iterate through the vertices in the bmesh
            for vert in bm.verts:
                # Get the global vertex coordinates
                global_co = obj.matrix_world @ vert.co
                # Print the vertex position in table format
                print(f"{count}; {obj.name}; {global_co.x:.2f}; {global_co.y:.2f}; {global_co.z:.2f};")
                count += 1

            # Free the bmesh data
            bm.free()

# Call the function to print vertex positions
print_vertex_positions()

```

In some case of experiments I have:  
`Python: Traceback (most recent call last): File "\Text.001", line 6, in <module> ValueError: The mesh must be in editmode`  
I believe that is possible to get for each object verts without option that manual must be in edit mode.

[https://docs.blender.org/api/current/bmesh.html](https://docs.blender.org/api/current/bmesh.html)

> There are two ways to access BMesh data, you can create a new BMesh by converting a mesh from [`bpy.types.BlendData.meshes`](https://docs.blender.org/api/current/bpy.types.BlendData.html#bpy.types.BlendData.meshes) or by accessing the current Edit-Mode mesh. See: [`bmesh.types.BMesh.from_mesh`](https://docs.blender.org/api/current/bmesh.types.html#bmesh.types.BMesh.from_mesh) and [`bmesh.from_edit_mesh`](https://docs.blender.org/api/current/bmesh.html#bmesh.from_edit_mesh) respectively.

---

<div class="post-metadata">

**Author:** ![ManBlender](https://blenderartists.org/user_avatar/blenderartists.org/manblender/32/811852_2.png) [@ManBlender](https://blenderartists.org/u/ManBlender)\
**Post date:** [April 28, 2024, 10:50am UTC](https://blenderartists.org/t/how-to-get-vertex-position-and-connected-vertices/1185279/5 "2024-04-28T10:50:59Z")

</div>

In short… I just want print gemotry node positions as are in tables, but for each object as name.

---

<div class="post-metadata">

**Author:** ![Secrop](https://blenderartists.org/user_avatar/blenderartists.org/secrop/32/20093_2.png) [@Secrop](https://blenderartists.org/u/Secrop)\
**Post date:** [May 19, 2024, 11:01am UTC](https://blenderartists.org/t/how-to-get-vertex-position-and-connected-vertices/1185279/6 "2024-05-19T11:01:53Z")

</div>

Have you looked into the Console output?  
Using the factory settings, just paste the script into the text editor and run it.  
It outputs the following:

```auto
No.; Name; Location x; Location y; Location z;
Object: Camera Type: CAMERA
Object: Cube Type: MESH
Processing mesh object: Cube
Mesh data: <bpy_struct, Mesh("Cube") at 0x000002AF47FCF208>
BMesh created
1; Cube; 1.00; 1.00; 1.00;
2; Cube; 1.00; 1.00; -1.00;
3; Cube; 1.00; -1.00; 1.00;
4; Cube; 1.00; -1.00; -1.00;
5; Cube; -1.00; 1.00; 1.00;
6; Cube; -1.00; 1.00; -1.00;
7; Cube; -1.00; -1.00; 1.00;
8; Cube; -1.00; -1.00; -1.00;
Object: Light Type: LIGHT

```

---

<div class="post-metadata">

**Author:** ![ManBlender](https://blenderartists.org/user_avatar/blenderartists.org/manblender/32/811852_2.png) [@ManBlender](https://blenderartists.org/u/ManBlender)\
**Post date:** [May 19, 2024, 11:49am UTC](https://blenderartists.org/t/how-to-get-vertex-position-and-connected-vertices/1185279/7 "2024-05-19T11:49:35Z")

</div>

Right… working… I expected a output in Python console not Blender Toggle System…  
It’s dissonance here… ;/
