# Check if selected loop is a disconnected loop using python

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

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

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)

• 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? – Omar Emara Jun 28 '16 at 15:07
• Yeah that angle works better, updated the script. – TLousky Jun 28 '16 at 15:20