Page MenuHome

Object.to_mesh() does not apply modifier if the object is disabled from the viewport
Open, Needs Triage by DeveloperPublic


System Information
Operating system: Windows 10 Home
Graphics card: GTX 1070 8GB

Blender Version
Broken: 2.81 beta, 125257758007, 2019-11-12
Worked: (optional)

Short description of error

I want to use the Python API to export an object mesh as a triangle mesh. I am doing this by adding a triangulate modifier to the object. When using to_mesh(), the modifier is not applied when the object is disabled in the viewport (Globally disable in viewports).

Here is a script that reproduces the issue

import bpy

cube_object ="Cube")
triangulation_mod ="triangulate", "TRIANGULATE")

depsgraph = bpy.context.evaluated_depsgraph_get()
obj_eval = cube_object.evaluated_get(depsgraph)
to_mesh_result = obj_eval.to_mesh()

print("Number of faces:", len(to_mesh_result.polygons))


Here is the output when the Cube object is disabled in the viewport:

Number of faces: 6

Here is the output when the Cube object is enabled in the viewport:

Number of faces: 12

This only seems to happen when using the Disable in Viewports icon. The Hide in Viewport icon does not reproduce the issue.

Exact steps for others to reproduce the error

I have attached a .blend file that contains the above script:

  1. Open .blend file
  2. Press 'Run Script'
  3. View console output

The number of faces is 6 when the Cube is disabled in viewports and 12 when enabled.



Event Timeline