BMesh.from_object(...)
Using the bmesh from object, can be written to another mesh as the deformed modified mesh.
Test script, writes context object deformed / modified mesh to new mesh "ObjBmesh"
import bpy
import bmesh
context = bpy.context
ob = context.object
dg = context.evaluated_depsgraph_get()
bm = bmesh.new()
bm.from_object(ob, dg)
bm.to_mesh(bpy.data.meshes.new("ObjBmesh"))
Using the evaluated object.
Further to the answer of @Somebody285 can get the evaluated objects from the depsgraph's objects collection.
Python console example, default cube has a subsurf modifier with default settings.
>>> dg = C.evaluated_depsgraph_get()
>>> cube = dg.objects.get("Cube")
>>> me = cube.to_mesh()
>>> len(me.vertices)
26
>>> len(cube.data.vertices)
26
me
is the evaluated (modifiers / shapekeys) applied mesh.
>>> me
bpy.data.meshes['Cube']
>>> D.meshes["Cube"]
bpy.data.meshes['Cube']
even tho it represents itself the same, it is not the base mesh object
>>> len(D.meshes["Cube"].vertices)
8
>>> me is D.meshes['Cube']
False
The original property of an object points to its unevaluated original.
>>> D.objects['Cube'].data is D.meshes['Cube']
True
>>> cube.original
bpy.data.objects['Cube']
>>> cube.original.data is D.meshes['Cube']
True
The object is evaluated, shown by its is_evaluated
property. The "evaluated mesh" does not have this set.
>>> cube.is_evaluated
True
>>> me.is_evaluated
False
However it is, as displayed in error message when trying to use it as a mesh data block.
>>> newcube = D.objects.new("Cube2", me)
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
RuntimeError: Error: Can not create object in main database with an evaluated data data-block
>>> newcube = D.objects.new("Cube2", cube.data)
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
RuntimeError: Error: Can not create object in main database with an evaluated data data-block
Copying gives us a mesh data block.
>>> newcube = D.objects.new("Cube2", cube.data.copy())