Object update without scene.update()

I have a loop over a set of polyhedra (PolyObject) where I shrinkwrap a sphere (CellObject) about each and generate a new mesh from the deformed sphere mesh. The ultimate goal is that I’d like to add these as shape keys while avoiding costly ops calls like modifier_apply.


    for j in range(0,nF):
        MyMesh=bpy.data.meshes.new("MyMesh_"+str(i).zfill(2)+"_"+str(j+1).zfill(2))
        PolyObject=bpy.data.objects["Poly_"+str(j+1).zfill(4)]
        Vertices=GlobalVertexList[i][j+1]    //Vertex and face data that I've previously read in from an external file.
        Faces=GlobalFaceList[i][j+1]         //                        
        
        MyMesh.from_pydata(Vertices,[],Faces)
        PolyObject.data=MyMesh
        
        CellObject.location=PolyObject.location                         

        MyMod=CellObject.modifiers.new("shrink"+str(j+1).zfill(2), type='SHRINKWRAP')
        MyMod.target=PolyObject
        MyMod.offset=0.0001

        MeshKey=CellObject.to_mesh(bpy.context.scene,True,'PREVIEW')
        CellObject.modifiers.remove(MyMod)
        Key1=CellObject.shape_key_add()
        for k,v in enumerate(MeshKey.vertices):
            Key1.data[k].co=v.co

When I run the code above, the resulting mesh from the to_mesh operator (MeshKey) is the exact same as the undeformed sphere mesh. By inserting a bpy.context.scene.update() before the to_mesh call works how I’d like. Unfortunately I’m working with around 8000 spheres with 81 polyhedra each which means doing that many scene updates would take too much time. Trying to update CellObject and PolyObject individually using object.data.update() doesn’t work. Am I asking the right question? What part of the update that happens during bpy.context.scene.update() am I missing?

The work that I eventually settled on was to end the loop after changing the CellObject’s location, inserting a scene update, and then re-running the loop with the remaining commands. Slower, but it works. Debugging gave about as much information as the hint that running a scene update fixes the problem. When the polyhedron object’s mesh is changed, the object gets tagged for updating. Because it does not get updated before the modifier is applied, the resulting mesh from to_mesh is effectively unmodified. And as far as I can tell, there is no straight-forward way through python to update individual objects.