1
$\begingroup$

I have some selected vertices that forms a loop,This loop may be disconnected or connected to other faces: Example

I want to check if it is disconnected or not using python.

$\endgroup$
3
$\begingroup$

enter image description here This will do the trick in your case:

import bpy, bmesh

bm = bmesh.from_edit_mesh( bpy.context.object.data )

selectedVerts = set( [ v.index for v in bm.verts if v.select ] )

bpy.ops.mesh.select_all( action = 'DESELECT' )
bpy.ops.mesh.select_non_manifold()

nonManifoldVerts = set( [ v.index for v in bm.verts if v.select ] )

commonVerts = selectedVerts.intersection( nonManifoldVerts )

bpy.ops.mesh.select_all( action = 'DESELECT' )
for i in selectedVerts: bm.verts[i].select = True
bm.select_flush( True )

msg = "Not connected" if commonVerts else "Connected"
print( msg )

EDITED:

This will now work with any loop that is completely manifold (i.e doesn't have any non-manifold edge/vert)

$\endgroup$
2
  • 1
    $\begingroup$ Well,I don't expect the user to always use a quad object,Is there is anyway it can be done universally? There is an operation for blender called select non manifold which select all disconnected vertices,You think we can use it to see if it is or not? $\endgroup$
    – Omar Emara
    Jun 28 '16 at 15:07
  • $\begingroup$ Yeah that angle works better, updated the script. $\endgroup$
    – TLousky
    Jun 28 '16 at 15:20
0
$\begingroup$

could be a detail but in a more advanced script maybe you need to keep the order of selection and the active vertex (last selected)

import bpy,bmesh

cao = bpy.context.active_object
bm = bmesh.from_edit_mesh(cao.data)
bm.normal_update()

verts_list=[v for v in bm.verts if v.select]

def disconnected(verts_list):
    
    history = bm.select_history[:] #bmesh selection history copy
    bpy.ops.mesh.select_all(action = 'DESELECT')
    bpy.ops.mesh.select_non_manifold()
    nonManifoldVerts={v for v in bm.verts if v.select}
    selectedVerts = set(verts_list)

    commonVerts = selectedVerts.intersection(nonManifoldVerts)

    bpy.ops.mesh.select_all(action = 'DESELECT')
    for v in verts_list: 
        v.select = True
    bm.select_history=history #first order of selection back
   

    if commonVerts:
        return True
    else:
        False

bmesh.update_edit_mesh(cao.data)

disconnected = disconnected(verts_list)
print("disconnected", disconnected) #True/False
$\endgroup$
1
  • 1
    $\begingroup$ Thanks for the answer. Could you explain what this code does and why it helps? $\endgroup$ Oct 1 '20 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.