In python how can I set random active Face in edit mode without toggle the Object/Edit Mode ?
For example re code in this answer can you also automatically set an active face again from the script to loop the option ?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
Random active face
Please heed the advice given in comments above. One of the (IMO) dopier rules on bse is the inability of new users to comment.
Here is a test script using method outlined in https://blender.stackexchange.com/a/81425/15543 Sets a random face active, and selects it.
import bpy import bmesh from random import randint def random_face(bm): bm.faces.ensure_lookup_table() return bm.faces[randint(0, len(bm.faces) - 1)] context = bpy.context ob = context.edit_object me = ob.data bm = bmesh.from_edit_mesh(me) print("before", bm.faces.active) bm.faces.active = random_face(bm) bm.faces.active.select = True print("after", bm.faces.active) bmesh.update_edit_mesh(me)
To also make the face the active select history
bm.select_history.add(bm.faces.active) print(bm.select_history.active is bm.faces.active)