0

I "discovered" a uv-layer called "NGon Face-Vertex".

My goal was to get get rid of all other uv-layers except the active one. So i wrote:

for layer in list(C.object.data.uv_layers):
   print("layer",layer)
   if not layer.active:
      C.object.data.uv_layers.remove(layer)

This code throws the error:

Traceback (most recent call last):
  File "<blender_console>", line 4, in <module>
RuntimeError: Error: Texture layer 'NGon Face-Vertex' not found

So i wonder where does this layer come from? Tried it with the default cube and blender version 2.82.8 Thought you people might find it interesing.

Here are some before/after screenshots: enter image description here enter image description here

Oh and this is how i do it now to circumvent this misterous layer:

for key in C.object.data.uv_layers.keys():
   layer = C.object.data.uv_layers[key]
   if not layer.active:
      C.object.data.uv_layers.remove(layer)

Edit: added working code to remove all layers but the active one

Mamu
  • 53
  • 6
  • You fell into the good old trap of modifying a list whilst iterating over it. This is not a blender related problem but a python (or even programming at large) problem. You can either iterate from last index to index 0, using for i in range(len(my_list), -1, -1): or while my_list: – Gorgious Nov 04 '20 at 14:31
  • 1
    Also FYI, the solution you used is also a good one to avoid this problem. In this case you are using a generated list of all the layer names, but it is independant of what happens to said layers afterwards. So there is no problem removing them from memory. To avoid any KeyError you can use the dictionary get as in layer = C.object.data.uv_layers.get(key). If the layer doesn't exist, the variable will be None Next line would then be if layer is not None and layer.active: – Gorgious Nov 04 '20 at 14:35
  • Oh no, i thought i'd got me covered with generating a shallow copy of the array by passing it to the list constructor: list(C.object.data.uv_layers). Either way, i am still wondering where this NGon Face-Vertex reference comes from? Do i maybe access one from another object because of my failed iteration? – Mamu Nov 04 '20 at 15:14
  • For example using: for non_active_layer in [layer for layer in C.object.data.uv_layers if not layer.active]: as the beginning of the for loop. and then removing it C.object.data.uv_layers.remove(non_active_layer) leads to the same error. – Mamu Nov 04 '20 at 15:20
  • I can't say I ever saw this uv layer name anywhere. Maybe one of the add-ons you are using automatically adds uv layers ? It doens't appear in the interface when you expand an object's uv maps ? – Gorgious Nov 04 '20 at 15:49
  • Added some screenshots. I now realize that the code does not leave the active layer but UVMap.001 as the one that's clicked on. I have to compare with C.object.data.uv_layers.active! The error with the misterious uv_layer still appears though. – Mamu Nov 05 '20 at 11:28
  • 3
    Related https://blender.stackexchange.com/questions/132670/how-to-find-and-delete-extra-uv-layers-on-many-objects – batFINGER Nov 05 '20 at 11:55

0 Answers0