I have been trying to figure this out from these posts:

Storing Face Indices in Data Arrays


How to get data and edit it on UV map edges?

But I'm just not following well enough to implement any of it!

I do not use the UI of Blender at all, so I never have a cursor, viewpoint etc. I would prefer to keep it this way if possible.

I am just working with the mesh of a cube for now, my code is...a mess from attempting to incorporate parts from the links above (amongst others) but essentially I just read in my mesh, turn it into a bmesh, use uv.smart_project, render the image of the uv_layer in a svg or png so I can see it (either with render.render or exporting the uv_layer directly). I have been trying to 'improve' how it is unwrapped by changing seams and even unwrapping by island but I need to know which faces are which, essentially I need to know if I can treat a heat function across the faces as continuous or if I need to do the individual faces and then handle the discontinuities. I'm very open to alternative ways of figuring out which faces are which too, I tried applying a different colour to each face but that doesn't work on the uv layer, and wouldn't show up when I tried rendering "scene" images!

Thank-you in advance for any help!

Update: I've got some code that is putting a label on each face, but for some reason it doesn't put the label I want, just "text" for all of them. I'm also not sure how to correctly access these, or properly associate them with the custom layer I create...or if that will transfer when I do the UV-unwrapping...

test_object = "/path/to/cube.stl"
bpy.ops.object.mode_set(mode='EDIT', toggle=True)

indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
jpg_path = os.path.join("/path/to/save/",
                        'face_labels' + '.jpg')

context = bpy.context
obj = context.edit_object
mesh = obj.data
bm = bmesh.from_edit_mesh(mesh)

def face_ID(face_ins: list, Mesh=bmesh.from_edit_mesh(mesh)):

    meshdata = bpy.context.active_object.data
    # custom int property on face
    selectionlayer = bm.faces.layers.int.get("Selection")
    # create one if one does not exist
    if not selectionlayer:
        selectionlayer = bm.faces.layers.int.new("Selection")

    for f, i in zip(bm.faces, faces_ins):
        f[selectionlayer] = i


    return mesh

def face_label(face_ins: list, savepath: str ):

    Mesh = face_ID(face_ins=indices)
    ob = bpy.context.active_object
    me = ob.data
    BM = bmesh.from_edit_mesh(me)   
    meshdata = bpy.context.active_object.data

    obj = bpy.context.active_object

    for poly, i in zip(meshdata.polygons, range(len(indices))):
        centre = poly.center
        ob = bpy.data.objects[text]
        ob.data.body = str(i)

  • $\begingroup$ Have you tried using the facemaps feature ? Facemaps allows you to select multiple faces and keep them in a group, even after geometry modification or UV unwraping. It is available up to Blender 3.6. In version 4 and above, you'll need an addon. $\endgroup$
    – Shaddo
    Commented Apr 8 at 16:55
  • $\begingroup$ Thanks for the suggestion but I'm on Blender 4.1 unfortunately, do facemaps allow you to tag each face/polygon in some way? Or would it be a case of relying on the order in the facemap not changing? $\endgroup$
    – Ciara
    Commented Apr 9 at 13:49


You must log in to answer this question.

Browse other questions tagged .