How to get and set face set values?

I’d like to write a script that can iterate over the a mesh that has had face set values set on it and be able to read and update the face set values. Is there a way to do this?

To get polygons, you can use bpy.types.Mesh.polygons.

import bpy
o = bpy.data.objects["Cube"]

# Get Polygons
for p in o.data.polygons:
    print("Vertex:" + str(p))

If you’re hoping to transform some polygons in edit-mode, you’re going to need to use the BMesh module as well in order for changes to be reflected in real-time. I made a demo of the module recently here.

It’s really hard to find API documentation about face sets because the keywords are so common but the information doesn’t seem to be stored in the mesh polygons.

https://docs.blender.org/api/current/bpy.types.MeshPolygon.html

It might be that the information is not available to the python API at all, only to the underlying C code. All I could find were operators, not direct data access.

Looks like this is still in development: https://devtalk.blender.org/t/accessing-face-sets-with-python/25685