PYTHON: bpy_extras.mesh_utils.mesh_linked_uv_islands Creates Exception in EditMode #86484

Closed
opened 2021-03-11 09:25:14 +01:00 by paul geraskin · 12 comments
Member

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?
tmp1.blend

image.png
image.png

Exact steps for others to reproduce the error

  • Open my blend file
  • Go to EditMode
  • Run a script. There will be Exception
**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? [tmp1.blend](https://archive.blender.org/developer/F9884598/tmp1.blend) ![image.png](https://archive.blender.org/developer/F9884599/image.png) ![image.png](https://archive.blender.org/developer/F9884602/image.png) **Exact steps for others to reproduce the error** - Open my blend file - Go to EditMode - Run a script. There will be Exception
Author
Member

Added subscriber: @PaulGeraskin

Added subscriber: @PaulGeraskin
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Can confirm

Can confirm
Member

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.

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.
Philipp Oeser self-assigned this 2021-03-11 11:37:50 +01:00
Member

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)
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) ```
Author
Member

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

Thank you! I'll write a small comment there.
Philipp Oeser removed their assignment 2022-01-18 21:03:54 +01:00
Member

Will have to concentrate on triaging for a while (and step down).

Will have to concentrate on triaging for a while (and step down).

This issue was referenced by 3cba80039d

This issue was referenced by 3cba80039d5db1d2d23ff754ab427f8ed66a71f8

Added subscriber: @Chris_Blackbourn

Added subscriber: @Chris_Blackbourn

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Chris Blackbourn self-assigned this 2022-08-27 06:35:54 +02:00

Use bpy_extras.bmesh_utils.bmesh_linked_uv_islands instead.

Use bpy_extras.bmesh_utils.bmesh_linked_uv_islands instead.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#86484
No description provided.