0

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 ?

batFINGER
  • 84,216
  • 10
  • 108
  • 233

1 Answers1

0

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.

Noticed your deleted post here re Deselect Neighbours Faces

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)
batFINGER
  • 84,216
  • 10
  • 108
  • 233