Select all verts that has 4 edges connected?

#1

How can I select all verts that has 4 edges connected to it? I need to get the “intersecting” verts. I figured the best way is to check if it has 4 edges connected.

0 Likes

#2

Something maybe like the following:

cube = bpy.context.active_object
bm = bmesh.from_edit_mesh(cube.data)

# Find all verts with exactly 4 edges coming into it
verts4 = [v for v in bm.verts if len(v.link_edges) == 4]

# i.e. using > 5 above will find you all of the nasty 6-poles in your topology etc.
0 Likes

#3

How can I only select the ones visible? If I hide parts, it still selects verts that has 4 edges even if it’s hidden.

What gets selected

What I need

0 Likes

#4

@AFWS:

Maybe this floats your boat?

import bpy
import bmesh

aob   = bpy.context.active_object

# 3D viewport should be in object mode
if not aob.mode == 'OBJECT' :
    bpy.ops.object.editmode_toggle()

fmesh = bmesh.new()
fmesh.from_mesh(aob.data)

# Ensure bmesh internal index tables are fresh
fmesh.verts.ensure_lookup_table()
fmesh.edges.ensure_lookup_table()
fmesh.faces.ensure_lookup_table()

# cand: verts member of exactly four edges and visible
cand = [v for v in fmesh.verts if v.hide == False and len(v.link_edges) == 4]

pick = list()
# Select candidates with all four neighboring vertices also visible
for v in cand :
    somehidden = False
    for e in v.link_edges :
        somehidden = somehidden or e.other_vert(v).hide
    if not somehidden :
        v.select_set(True)
        pick.append(v)
    else :
        v.select_set(False)
    
# Sync up bmesh and mesh
fmesh.to_mesh(aob.data)
0 Likes

#5

@grosgood

OK, just got around to testing this. Doesn’t seem to do what I need. Any verts that has 4 edges visible ,but has more edges that’s hidden, doesn’t get selected. Might not be possible to do.

0 Likes

#6

Why not use Select Similar - connected edges?

bpy.ops.mesh.select_similar(type=“EDGE”)

or if you dont need it via script, shift g -> connected edges

0 Likes

#7

Ah! Well then. Perhaps this floats your boat…

import bpy
import bmesh

aob   = bpy.context.active_object

# 3D viewport should be in object mode
if not aob.mode == 'OBJECT' :
    bpy.ops.object.editmode_toggle()

fmesh = bmesh.new()
fmesh.from_mesh(aob.data)

# Ensure bmesh internal index tables are fresh
fmesh.verts.ensure_lookup_table()
fmesh.edges.ensure_lookup_table()
fmesh.faces.ensure_lookup_table()

# cand: verts with membership in four or more edges and are also visible
cand = [v for v in fmesh.verts if v.hide == False and len(v.link_edges) > 3]

# Container for vertices that meet our criteria
pick = list()
# Select candidates with exactly four neighboring visible vertices
for v in cand :
    visibleneighbors = []
    for e in v.link_edges :
        if e.other_vert(v).hide == False :
            visibleneighbors.append(e.other_vert(v))

    # Select vertices with exactly four visible neighbors
    if len(visibleneighbors) == 4 :
        v.select_set(True)
        pick.append(v)
    else :
        v.select_set(False)
    
# Sync up bmesh and mesh
fmesh.to_mesh(aob.data)

# Do what you will with the vertices inside pick...

This concludes the useful portion of this post. What follows is a little…
<rant>
“I aim for the stars… but sometimes I hit London.”

– “Major William Taggert” [played by actor James Daley], a trenchant reinterpretation of one of Wernher von Braun’s aspirations. Aim for the Stars, a 1960 Columbia Pictures film.

`Tis one of the more capricious facets of our human existence that the actual meaning of the words we dispatch off to readers can differ greatly from our intended meaning.

Why do we screw up what ought to be concomitant things?

Methinks that the focus we maintain in trying to express our intended ideas actually distorts our perception of the marks we entrain for our readers. We observe the marks, but read into them our intents instead.

A disconnect: we read what we think we have written, but not what we wrote.

It is a bit of a trick, but when it comes to proofing, we really need to induce a complete, but temporary, amnesia about our intents so that we may read what we’ve written without the crosstalk of our intents getting in the way.

Then, when we have fully grasped what we have written – and only j ust what we’ve written – we can release ourselves from our self-induced amnesia and determine if our intents and our writings coincide.

Self-induced amnesia happens to be very hard to achieve. But as servants to our readers, it is our manifest obligation to ensure that the marks we entrain on paper, be it virtual or physical, really do reflect our intended communications. Because it is only the marks that convey meaning. The intent between our ears is forever opaque to all the others outside of us.
</rant>

@AFWS
The difficulty I have is that your expression of needs is a moving target. I don’t think you have any malicious intents whatsoever, but you are unintentionally omitting ideas, are not asking what you intend to ask and are not aware that you are subjecting us to scope creep.

In light of my rant, I request that you actually read how you titled this post and what you actually asked in the initial go-around. Seeing only what you wrote, and unable to read your mind, @deadpin gave a very servicable reply, I think. Your reply gave rise to a second requirement - new to the game - that hidden vertices were also a material aspect of your needs. I took a whack at that. From that came another variant-of-needs, one which drifts from your initial question. It is not a pattern of actual connectivity that you need to detect, but a pattern of apparent connectivity of visible vertices in a mesh with randomly hidden ones.

That is what your first question should have conveyed in the initial go around. Closing the gap between expression and intent is a writer’s obligation to readers, even in something as simple as a post, a text message, anything.

I hope the code helps. Take care.

0 Likes