How to get vertex position and connected vertices?

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!

Have you tried to use bmesh?

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)

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

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

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

There are two ways to access BMesh data, you can create a new BMesh by converting a mesh from bpy.types.BlendData.meshes or by accessing the current Edit-Mode mesh. See: bmesh.types.BMesh.from_mesh and bmesh.from_edit_mesh respectively.

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

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:

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

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