I want to split a mesh with random_selection.
My question is: How do I make sure that the "random_selection", selects the faces in a mesh to exact no. as specified by percentage. for example: A 10*10 Mesh contains 100 faces, so 50% of random selection should select exactly 50 faces, but in reality it selects sometime 48, 51, and so on.
here is my noob Code:
import bpy import bmesh myob = bpy.ops.mesh m = bpy.context.object me = m.data bpy.ops.mesh.select_all(action='TOGGLE') bm = bmesh.from_edit_mesh(m.data) face = bm.faces myob.select_random(percent=50.0) if len(bm.faces.select) == 100*50/100: bpy.ops.mesh.split else: Pass
I am newbei in Python scripting and blender APIs does not helping me in understanding it clearly on 'How to get access the face information in a mesh'
len(bm.faces) # Will tell the total faces in a mesh bm.faces[i].select = true # Will select one face at a time
but, how do I know, How much faces are exactly been selected. Any suggestion:
Here is some code I tried:
for i in range(100): if bm.faces[i].select: fac.append(bm.faces[i]) count += 1 if len(fac) < 50: for i in range(50): if bm.faces[i].select == False: bm.faces[i].select = True fac.append(bm.faces[i]) continue bmesh.update_edit_mesh(m.data, True) elif len(fac) > 50: print (count - 50, "are extra faces." ) for j in range(100): if bm.faces[j].select == True: bm.faces[j].select = False if bm.faces[j] in fac: del fac[j] #problem here continue bmesh.update_edit_mesh(m.data, True) else: print ("Exactly 50 faces are selected")
I somehow manage to select missing faces to make them 50 faces, but how do I deselect and remove them from list of selected faces.