The first question
As Markus von Broady said, it's more convenient to keep the data so you can use it later.
So I suggest to use a dictionary with an intersection vertex as key and a set of linked ones as value.
intersection_dic = {}
#do loop
connected_verts.remove(vert.index)
intersection_dic[vert.index] = connected_verts
import bpy
bpy.ops.object.mode_set(mode='OBJECT')
obj = bpy.context.active_object
mesh = obj.data
vg = obj.vertex_groups.new(name="Intersection_Points")
intersection_dic = {}
# Loop through all vertices in the mesh
for vert in mesh.vertices:
connected_verts = set()
# Loop through all edges connected to the vertex
for edge in mesh.edges:
if vert.index in edge.vertices:
connected_verts.update(edge.vertices)
if len(connected_verts) >= 4:
vg.add([vert.index], 1.0, 'ADD')
connected_verts.remove(vert.index)
intersection_dic[vert.index] = connected_verts
The seconde question
You can use the itertools module to create sets of 3 vertex indices like your drawing. That module contains itertools.combinations.
import itertools
for vc, value in intersection_dic.items():
print(f"[{vc}]")
for va, vb in itertools.combinations(value, 2):
print(f"{va} - {vc} - {vb}")
outcome
[4]
8 - 4 - 1
8 - 4 - 2
1 - 4 - 2
[5]
0 - 5 - 1
0 - 5 - 8
1 - 5 - 8
[6]
0 - 6 - 8
0 - 6 - 3
8 - 6 - 3
[7]
8 - 7 - 2
8 - 7 - 3
2 - 7 - 3
[8]
4 - 8 - 5
4 - 8 - 6
4 - 8 - 7
5 - 8 - 6
5 - 8 - 7
6 - 8 - 7
About BMesh
You can easily get connected_verts using using bmesh.
intersection_dic = {}
for vert in bm.verts:
if len(vert.link_edges) < 3:
continue
connected_verts = [e.other_vert(vert).index for e in vert.link_edges]
intersection_dic[vert.index] = connected_verts
dvert = vert[dvert_lay]
dvert[group_index] = 1.0
connected_verts
to an empty list, discarding data obtained in previous iterations… $\endgroup$