1
$\begingroup$

How to check, if selected edges is a continuous line? Note that one edge is deselected. enter image description here

$\endgroup$
3

2 Answers 2

1
$\begingroup$

Found some quick workaround. Checking how many verts with only one edge in selection. If 2, then line is single without branches

import bpy
import bmesh

# Get the active object and its Bmesh
obj = bpy.context.active_object
bm = bmesh.from_edit_mesh(obj.data)

# Get the selected vertices
selected_verts = [v for v in bm.verts if v.select]

# Create a dictionary to store the edge indices for each vertex
vert_edges = {}

# Loop through the selected vertices and add their edge indices to the dictionary
for vert in selected_verts:
    edges = [e.index for e in vert.link_edges if e.select]
    vert_edges[vert.index] = edges

# Get verts with only one edge
ends = [vert_index for vert_index, edge_index in vert_edges.items() if len(edge_index) == 1]

if len(ends) > 2:
    print("Bad: Line have more than 2 ends")
else:
    print("Good: Line have 2 ends")
$\endgroup$
1
$\begingroup$

Just a shorter version without bmesh:

import bpy
bpy.ops.object.mode_set(mode='OBJECT')
obj = bpy.context.active_object
mesh = obj.data
bpy.ops.object.mode_set(mode='EDIT')

# get all verts_indices of selected edges with double entries if v is part of 2 edges
verts = list(sum([e.vertices[:] for e in mesh.edges if e.select],()))

# check if only 2 verts are unique
if len([idx for idx in verts if verts.count(idx) == 1]) == 2:          
    print("Good: all edges connected")
else:
    print("Bad: not all edges connected")
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .