object.to_mesh ignores object.update_from_editmode #63244

Closed
opened 2019-04-03 11:47:38 +02:00 by Mikhail Rachinskiy · 11 comments

System Information
Operating system: Windows-10-10.0.17134 64 Bits
Graphics card: GeForce GTX 860M/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 417.35

Blender Version
Broken: version: 2.80 (sub 53), branch: blender2.7, commit date: 2019-04-02 19:53, hash: a813e259d6
Worked: This might be the cause 46eb5a0b8a

Short description of error
obj.update_from_editmode updates obj.data but not the result of the obj.to_mesh as it was before.

bmesh.from_object also does not update, but it did not work before unlike to_mesh.

Why there is no easy way of getting evaluated mesh from edit mode? depsgraph.id_eval_get(obj).data works only from object mode, and to_mesh creates a whole new mesh datablock which I don't need.

Exact steps for others to reproduce the error

  • Open attached blend file: ob_update.blend
  • Run the script from Text Editor > popup shows up which tells there is 1 selected face.
  • No matter how you change the face selection in 3D view, it will always show 1 face selected, unless you leave and re-enter edit mode.
**System Information** Operating system: Windows-10-10.0.17134 64 Bits Graphics card: GeForce GTX 860M/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 417.35 **Blender Version** Broken: version: 2.80 (sub 53), branch: blender2.7, commit date: 2019-04-02 19:53, hash: `a813e259d6` Worked: This might be the cause 46eb5a0b8a **Short description of error** `obj.update_from_editmode` updates `obj.data` but not the result of the `obj.to_mesh` as it was before. `bmesh.from_object` also does not update, but it did not work before unlike `to_mesh`. Why there is no easy way of getting evaluated mesh from edit mode? `depsgraph.id_eval_get(obj).data` works only from object mode, and `to_mesh` creates a whole new mesh datablock which I don't need. **Exact steps for others to reproduce the error** - Open attached blend file: [ob_update.blend](https://archive.blender.org/developer/F6908776/ob_update.blend) - Run the script from Text Editor > popup shows up which tells there is `1` selected face. - No matter how you change the face selection in 3D view, it will always show `1` face selected, unless you leave and re-enter edit mode.
Author
Member

Added subscriber: @MikhailRachinskiy

Added subscriber: @MikhailRachinskiy
Sergey Sharybin was assigned by Sebastian Parborg 2019-04-03 13:11:49 +02:00

Added subscriber: @TakeshiFunahashi

Added subscriber: @TakeshiFunahashi

Added subscriber: @JoseConseco

Added subscriber: @JoseConseco

Added subscriber: @MACHIN3

Added subscriber: @MACHIN3

Added subscriber: @brecht

Added subscriber: @brecht

In order to properly get mesh with modifier applies the dependency graph is to be evaluated first. What happens in this script is that it does modify the original object (by doing update_from_editmode), but it does not inform dependency graph about it. There are two ways to go about it:

  1. Tag object for update and make sure the dependency graph is re-evaluated by calling this after update_from_editmode:
ob.update_tag()
bpy.context.view_layer.update()
  1. Request mesh without modifiers applied, by doing me = ob.to_mesh(bpy.context.depsgraph, False)

@brecht, do you think there is some way we should improve/change API here, or add some sanity checks?

In order to properly get mesh with modifier applies the dependency graph is to be evaluated first. What happens in this script is that it does modify the original object (by doing `update_from_editmode`), but it does not inform dependency graph about it. There are two ways to go about it: 1. Tag object for update and make sure the dependency graph is re-evaluated by calling this after `update_from_editmode`: ``` ob.update_tag() bpy.context.view_layer.update() ``` 2. Request mesh without modifiers applied, by doing `me = ob.to_mesh(bpy.context.depsgraph, False)` @brecht, do you think there is some way we should improve/change API here, or add some sanity checks?
Author
Member

This change in behaviour could be mentioned in 2.80 Py API Changes .
I will also create Q&A on stackexchange.
This might be enough to keep people informed.

This change in behaviour could be mentioned in [2.80 Py API Changes ](https://wiki.blender.org/wiki/Reference/Release_Notes/2.80/Python_API). I will also create Q&A on stackexchange. This might be enough to keep people informed.

@MikhailRachinskiy, agree. There is still a huge work to be done on documentation and release logs, and this indeed something what should be mentioned there.

@MikhailRachinskiy, agree. There is still a huge work to be done on documentation and release logs, and this indeed something what should be mentioned there.

I really thanks Mikhail make this report, and Sergey offer way how to up-date correctly.

There seems case, even though I do not use "update_from_editmode",
I need to add "ob.update_tag() bpy.context.view_layer.update()" in sipite of "ob.data.update()"
After that, function, which overwrite shape key data, suddenly work again.
(it seems break after this commit)

def apply_vert_coords(ob, mesh, x):
    for i, v in enumerate(mesh):
        v.co = x[i]
    ob.update_tag() 
    bpy.context.view_layer.update()
    ob.data.update()

The "mesh" argument is, active_shape_ key.data of object.
then x = editted vertices with use object_to.mesh()

I still not clear understand when I actually need to use Sargey Recommend way.
then hope new API document follow these detail too.

I really thanks Mikhail make this report, and Sergey offer way how to up-date correctly. There seems case, even though I do not use "update_from_editmode", I need to add "ob.update_tag() bpy.context.view_layer.update()" in sipite of "ob.data.update()" After that, function, which overwrite shape key data, suddenly work again. (it seems break after this commit) ``` def apply_vert_coords(ob, mesh, x): for i, v in enumerate(mesh): v.co = x[i] ob.update_tag() bpy.context.view_layer.update() ob.data.update() ``` The "mesh" argument is, active_shape_ key.data of object. then x = editted vertices with use object_to.mesh() I still not clear understand when I actually need to use Sargey Recommend way. then hope new API document follow these detail too.

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Committed extra changes in d4f12860aa which makes this usecase a bit more simple.

Here is a script ported to all the recent dependency graph API changes.

import bpy

ob = bpy.context.object
ob.update_from_editmode()

depsgraph = bpy.context.evaluated_depsgraph_get()
ob_eval = ob.evaluated_get(depsgraph)

me = ob_eval.to_mesh()
i = len([poly for poly in me.polygons if poly.select])
ob_eval.to_mesh_clear()

def draw(self, context):
    self.layout.label(text=str(i))

bpy.context.window_manager.popup_menu(draw, title="Faces selected")

Thanks for the report, considering it solved now.

Committed extra changes in d4f12860aa which makes this usecase a bit more simple. Here is a script ported to all the recent dependency graph API changes. ``` import bpy ob = bpy.context.object ob.update_from_editmode() depsgraph = bpy.context.evaluated_depsgraph_get() ob_eval = ob.evaluated_get(depsgraph) me = ob_eval.to_mesh() i = len([poly for poly in me.polygons if poly.select]) ob_eval.to_mesh_clear() def draw(self, context): self.layout.label(text=str(i)) bpy.context.window_manager.popup_menu(draw, title="Faces selected") ``` Thanks for the report, considering it solved now.
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
5 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#63244
No description provided.