select faces with poygon method how to ?

I tried the command

f.select_set(True)

but it did not select the faces

how if possible can it be done ?

thanks

on a wrapped bmesh object?

you need to call

bmesh.update_edit_mesh(me, False, False)

to let the viewport refresh

do you also need to do

bm.to_mesh(object.data)
bm.free()

did not see these in given example !

thanks

if it’s wrapped then no.

I got script to work and on console I can see before and after selected faces
but in viewport it does not show the same thing !

is this working or bug ?

will do some more testing

here is sample file run func and see console
faces selection seems ok
but nothing show in viewport !

zsel1.blend (96.5 KB)

note: I already remove the free command at the end

is this unwrap needed when changing faces selected or only when changing verts data

if I add the last 2 commands

bm.to_mesh(me)
bm.free()

then it seems to select all faces in viewport
but on console it did not select all faces !

thanks

You’re not working with a wrapped bmesh, so a call to bmesh.update_edit_mesh() is useless.

The bmesh object you work with has nothing to do with the mesh you see in viewport. There’s no other way to replace the original mesh with bm.to_mesh() to get the bmesh with different selection state to the viewport.

This is a lot faster:

import bpy
import bmesh
from mathutils import Vector
from time import time

def sel1():

    begin = time()
    
    ob = bpy.context.object
    me = ob.data
    bm = bmesh.from_edit_mesh(me)
    bm.normal_update()
    
    up = Vector((0,0,1))

    for f in bm.faces:
        f.select = False
    bm.select_flush(False)
    
    for f in bm.faces:
        if round(f.normal.dot(up), 1) != -1.0:
            f.select = True
    bm.select_flush_mode()

    bmesh.update_edit_mesh(me, False, False)
            
    end = time()
    print('Execution took : ', time()-begin, 'seconds')
    
sel1()

I did not have the right command !

what does this one do ?
f.select_set(True)

not certain the dot product is enough to make the difference
but will test it also !

thanks

dot product does not require an a cos^-1, so yes, it is faster.

f.select_set(True) selects the face…

ok but what is the difference with f.select = True

is it the same why ?

have to review my algo dont’ even need the angle to zup I think!
normal should be enough

how come the normal may have some values that are not 0 or 1 but close to it?

instead of 0 you get 0.0014

thanks

.select is a property, .select_set() is a method. The latter flushes selections immediately and is thus slower, manual flushing is usually required for the former. For mixed selection changes, select_set() is sometimes required.

Floating point precision can be the cause, especially for a normal which is normalized to 0…1