Get vertex position with subdivsions without apply modifier

Hi,

I have got this code to print vertex position:

import bpy  
  
current_obj = bpy.context.active_object  
  
print("="*40) # printing marker  
for face in current_obj.data.polygons:  
    verts_in_face = face.vertices[:]  
    print("face index", face.index)  
    print("normal", face.normal)  
    for vert in verts_in_face:
        local_point = current_obj.data.vertices[vert].co
        world_point = current_obj.matrix_world * local_point
        print("vert", vert, " vert co", world_point)  

The code works fine, but, there is a problem. If I add a Subdivision modifier, the vertex is not in the same place in world coordinates.

How can I get the position AFTER subdivision without apply the modifiers?

You need to apply the modifier in one or the other way, via operator or to_mesh() - which creates a new mesh datablock.

Ok, but how can apply the modifier “on the fly”. I mean, only to get the vertex data, but not a “real” apply the modifier?

I want the new vertex data, but I don’t want to remove the modifier from the modifier stack.

what’s wrong with to_mesh()? I believe it’s faster than its bmesh module equivalent (which would be entirely in-memory).

I have never used to_mesh(), can you tell me where can I find API doc’s?

About, bmesh… is this the best way to get selected vertices?


bm = bmesh.from_edit_mesh(myobject.data)
for v in bm.verts:
     if v.select:
           mylist.extend([v.index])

http://www.blender.org/api/blender_python_api_2_74_release/bpy.types.Object.html?highlight=to_mesh#bpy.types.Object.to_mesh

This is probably better: [v for v in bm.verts if v.select]

After the all important missing import bmesh
It says it has to be in edit mode, so I guess that doesn’t work for me.
Any other ideas that are better then having to apply the subdivision modifier to see the actual post modifier vertices in python code?

I see now using to_mesh is not applying it permanently like the GUI action does, as long as you remove it after.

aom = ao.to_mesh(ctx.scene, True, “PREVIEW”)bpy.data.meshes.remove(aom)