1
$\begingroup$

I was keen on finding a python script that checks if all my meshes faces are quads.

pseudocode:

nonquad = 0
for i in selected_facelist:
    if count(selected_facelist.verts) > 4:
       nonquad +=1
print "Found :",nonquad,"Non Quads"

I dont know the API for THE CURRENT Blender 2.8. Any help is much appreciated

or if there is a pre-built button in blender.

$\endgroup$
6
$\begingroup$

I suppose your goal here is not for the script, as you say "or if there is a pre-build button".

So in edit mode, set the selection mode to 'face', select any quad and use the menu "Select/Select similar/Polygon Sides".

Once done you have all the quads, simply invert the selection with CtrlI to obtain non quad polygons.

enter image description here

The selection operators are dependent on the selection mode (vertex, edge, face), have a look at the menu for each case.

You may also want to select 'all by traits' to know if there is non manifold parts or loose geometry in your model.

If needed a commented script:

import bpy

# Go to object mode so that we can select
bpy.ops.object.mode_set(mode = 'OBJECT')

# Get active object
obj = bpy.context.active_object

# Select non quad faces (polygons)
for p in obj.data.polygons:
    p.select = len(p.vertices) != 4

# Go in edit mode to show the result    
bpy.ops.object.mode_set(mode = 'EDIT') 
$\endgroup$
4
$\begingroup$

You can use Bmesh module in Edit Mode based on your selection:

import bpy
import bmesh

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

for f in bm.faces:
    if f.select == True:
        if len(f.verts) == 4:
            print("Is quad", f)
        elif len(f.verts) == 3:
            print ("Is triangle", f)
        else:
            print ("Is N-gon", f)

# Just in case...
bmesh.update_edit_mesh(obj.data)

Related: How to read vertices of quad faces using Python API?

$\endgroup$

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.