I've been scouring the Blender Python API docs for a way to get access to the mesh data that is displayed in the view-port. (with modifiers applied - WYSIWYG)
For reference, this was possible with the 2.4x API's
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
The option to apply modifiers is common for exporters included with Blender, so you can check how they do it.
Typically you can use the
Object.to_mesh function, which returns a new mesh. You can manipulate it without distructively editing the user's data.
import bpy # --- setup variables --- context = bpy.context scene = context.scene # assume we have an object with geometry, nurbs, metaball, curves... _not_ a lamp obj = context.object # --- get a mesh from the object --- apply_modifiers = True settings = 'PREVIEW' mesh = obj.to_mesh(scene, apply_modifiers, settings) # ... do something with the mesh ...
It's important to remove the mesh, unless you have explicitly assigned it to an object. Otherwise it will be stored in Blender until the file is saved and loaded again.
# optionally remove it bpy.data.meshes.remove(mesh)