7
$\begingroup$

I'm trying to find a way to save selection faces, tried Vertex Group, the issue with Vertex Group is that it adds the faces that are marked by 4 vertices that are added to the Vertex Group, there are some cases were this doesn't apply, the image explains what I mean. So is there a way to save my selected faces, so I don't have to go through the whole process of reselecting them each time I need to do so? If you check the image, I didn't assign the hatched faces to the Vertex Group, still when I select the Vertex Group, they get selected, I understand that they got selected because the four boundary vertices are assigned to the Vertex Group, I need to save only face selection, not vertex selection.
Faces I don't want to be added to selection

$\endgroup$
12
$\begingroup$

This is a limitation of the current Vertex Groups system that has been an occasional nuisance.

That's is why they are called Vertex Groups, not "Face Groups"; selections of vertex don't unequivocally define groups of faces, since a vertex can belong to an arbitrary number of them.

Would be nice to hear about more options and solutions for this from other users around here. The way I generally solve this is by using material slots instead, if you don't mind the additional pollution in the materials list.

Go to Properties Window > Materials Tabs > Add New Material Slot button, and then with the desired faces selected press the Assign button.

Since they work on a per-face basis instead of single vertex, they can correctly define face groups. You can still assign materials independently, but you can't have a face belong to more than one slot unfortunately, so you may end up having several slots with the same materiel.

Different intersections of selections overlapping materials may require an exponentially growing number of slots.

$\endgroup$
  • $\begingroup$ But that will change the material, right? $\endgroup$ – Georges Apr 23 '16 at 22:41
  • $\begingroup$ Yeah I guess this is the best solution, in case I need several groups of faces to have the same material, I just have to copy, rename and keep same parameters. Thanks! $\endgroup$ – Georges Apr 23 '16 at 22:50
  • $\begingroup$ Yeah, you can use the same material on multiple slots of the same object. You'll get some redundancy, but I guess it's better than nothing. $\endgroup$ – Duarte Farrajota Ramos Apr 24 '16 at 0:46
3
$\begingroup$

It's possible to store the selection state into a Vertex Color map.

The following script creates a vertex color map Selection with a black face for every selected face and a white face for every non-selected. Strictly speaking this would be “every vertex of every polygon”. But the main difference to vertex groups is that each vertex appears multiple times in the vertex color map – once for every polygon that it's part of. So it's possible identify the faces by their vertices.

import bpy
obj = bpy.context.active_object
me = obj.data
bpy.ops.object.mode_set(mode='OBJECT')
col = me.vertex_colors.new('Selection')

for poly in me.polygons:
    for l_ix in poly.loop_indices:
        if poly.select:
            col.data[l_ix].color = (0, 0, 0)

bpy.ops.object.mode_set(mode='EDIT')

The following script restores the selection from the vertex color map.

import bpy, bmesh
from mathutils import Color

bpy.context.tool_settings.mesh_select_mode = (False, False, True)

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT')

obj = bpy.context.active_object
me = obj.data
bm = bmesh.new()
bm.from_mesh(me)
col = me.vertex_colors['Selection']

for (poly, bm_poly) in zip(me.polygons, bm.faces):
    l_ix = poly.loop_indices[0]
    # Only look at first vertex as all should have same color
    if col.data[l_ix].color == Color((0, 0, 0)):
        bm_poly.select_set(True)

bm.to_mesh(me)
bm.free()
bpy.ops.object.mode_set(mode='EDIT')

By adjusting the name of the vertex color map you can store multiple selections for every object.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.