Page MenuHome

PYTHON: bpy_extras.mesh_utils.mesh_linked_uv_islands Creates Exception in EditMode
Confirmed, NormalPublic

Description

Blender Version
Broken: 2.92 official release

Short description of error
I tested bpy_extras.mesh_utils.mesh_linked_uv_islands function. It works nice in ObjectMode but it creates an error in EditMode. Is it a bug?


Exact steps for others to reproduce the error

  • Open my blend file
  • Go to EditMode
  • Run a script. There will be Exception

Event Timeline

Philipp Oeser (lichtwerk) changed the task status from Needs Triage to Confirmed.Mar 11 2021, 10:34 AM
Philipp Oeser (lichtwerk) added projects: Python API, Restricted Project.

Can confirm

Sorry, forgot that this is a general case, the way the script accesses mesh data is not suited for editmode

https://docs.blender.org/api/master/bpy.types.Mesh.html

The mesh data is accessed in object mode and intended for compact storage, for more flexible mesh editing from python see bmesh

So, uv_layers is not available in editmode.

We could go through bmesh instead (then to be found in uv_layer = bm.loops.layers.uv.active) or switch to objectmode in this case (think this is what most scripts do?)

In any case, we should not throw an error.

I have put up a patch preventing the error [and going through bmesh if in editmode].
I am unsure though if bmesh is allowed inside mesh_utils, so outcome might just be that mesh_linked_uv_islands will return an empty list instead.

But of course you will want to have this working in editmode, so for now you can also just do

is_editmode = (ob.mode == 'EDIT')
if is_editmode:
  bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

do the call
       
if is_editmode:
  bpy.ops.object.mode_set(mode='EDIT', toggle=False)

Thank you! I'll write a small comment there.