# How to get Blender to add new face-ids but not recalculate old face-ids?

I am writing a procedural planet generation addon.

I thought it would be nice to give the user the ability to create continents. He can create a continent, give it a name and add some faces to it (via selection). The addon is storing the face-indices of the current selected faces. If a user selects a continent in the gui the corresponding faces are selected, too.

Now I found out (via extrude operator, Find out if Mesh Operator (bpy.ops.mesh...) was cancelled or not via python) that blender sometimes recalculates the index of old faces. That is destroying my addon and the way I store the continents (remeber: face-indices).

How can I force blender to only add new face-indices for the newly created faces and leave the old faces alone?

Thanks for helping!

## 1 Answer

Geometry element indices can change at any time, don't rely on them!
See e.g. How are vertex indices determined?

You should instead use a custom data layer to store the group (continent) information in. I would suggest bm.faces.layers.int. How to display them in a panel is a bit tricky, because you need to iterate the entire mesh before you know which numbers / continents exist.

Note that if a user extrudes a face that is part of a continent already, then that property might be copied to the new faces. It's definitely true for vertex extrusion, but I'm not entirely sure when or which faces may receive the custom properties of their ancestors. Also see second half of my answer here: https://blender.stackexchange.com/a/36816/1363

Another approach would be to use Vertex groups. There are some downsides however: Vertices can be assigned with weights, they can be assigned to multiple groups and the face selection may differ for certain topologies (3 adjacent faces, left and right part of a continent, the middle one not will select all 3 if vertex groups are used, since all of the vertices are used by the left and right face).

• Meh ... That is really frustrating. The addon is for my thesis and now I need to rework everything :( Thanks for the info. Sep 3 '15 at 19:25
• Would I be able to store the faces itself in a different collection? For example a continent has a faces-set and I would add the faces itself to the set. So I would not need custom data layers or vertex groups and could get the current working index of the faces which are stored in the set. Sep 3 '15 at 19:39
• No, they rare not really hashable and you cannot store direct references with Python (at least not persistently, and without causing crashes because references can become invalid). You would need to implement this in native code, similar to vertex groups. If this is a proof of concept, then go for the CD layer, even if the panel code will be slow. You could improve that with some kind of cache, to at least rate-limit the checks. Proper invalidation is not possible either with Python. You could also provide a button for the user to press to update the list of available continents. Sep 3 '15 at 20:47