0
$\begingroup$

How can I assign a script from the theme below to any button? And also make it possible to adjust the TOL parameter after applying the button. I tried to do this through scripting, bind the script to the button and bring it to the panel, and then add it to the quick, but it doesn't look very convenient. How can this be simplified?

Is there a way to select Non-Planar Faces?

import bpy
import bmesh
from mathutils.geometry import (
            distance_point_to_plane,
            normal)

context = bpy.context
obj = context.edit_object
mesh = obj.data

TOL = 0.001

# select None
bpy.ops.mesh.select_all(action='DESELECT')
bm = bmesh.from_edit_mesh(mesh)
ngons = [f for f in bm.faces if len(f.verts) > 3]

for ngon in ngons:
    # define a plane from first 3 points
    co = ngon.verts[0].co
    norm = normal([v.co for v in ngon.verts[:3]])

    ngon.select =  not all(
        [abs(distance_point_to_plane(v.co, co, norm)) < TOL
        for v in ngon.verts[3:]])

bmesh.update_edit_mesh(mesh)
```
$\endgroup$
2
  • 1
    $\begingroup$ Check the Python API docs (next to the manual on the docs.blender.org page), and look into making an add-on. $\endgroup$
    – TheLabCat
    Commented Apr 15 at 15:39
  • $\begingroup$ Make the tolerance (TOL) a FloatProperty, and create an Operator for the script. (Here is an example). The operator can be called by a button and by Edit > Operator Search ... from the main menu. The add-on creates the button, binds the operator, assigns a shortcut, creates a panel, etc. The tolerance can be changed in the Adjust Last Operation popup (F9) when the operator is called. Or bind it to an input box. $\endgroup$
    – Blunder
    Commented Apr 15 at 22:07

0

You must log in to answer this question.

Browse other questions tagged .