Return vertices to location

Requst for a python script,

I dont know if this is possible but could someone write a python script, so that you could select a group of vertices, and then store all their locations, then make it so later on (after doing other mesh work), you could push a button and return the group of vertices back to their stored location ?? If this can be done could someone please make a script to do this for me ??

your probably best of using shape keys for this.

Shape keys might probably be the best solution indeed, but here’s a python way to do it:

import Blender
from Blender import*

def Store():
    obs = Object.GetSelected()
    if len(obs)==0:
        Draw.PupMenu("Error%t|No object selected")
    elif obs[0].type!='Mesh':
        Draw.PupMenu("Error%t|Selected object isn't a mesh")
    else:
        me = Mesh.Get(obs[0].getData(True,True))
        editmode = False
        if Window.EditMode():
            editmode = True
            Window.EditMode(0)
        
        if len(me.verts.selected())==0:
            Draw.PupMenu("Error%t|No vertices selected")
        else:
            sel = me.verts.selected()
            store = []
            for i in sel:
                loc = me.verts[i].co
                store.append([i,loc])
            d = {}
            d['locs'] = store
            Blender.Registry.SetKey('StoreVertLoc',d, False)

        if editmode:
            Window.EditMode(1)

def Retrieve():
    d = Registry.GetKey('StoreVertLoc', False)
    if d:
        try:
            stored = d['locs']
        except:
            stored = False
        if not stored:
            Draw.PupMenu("Error%t|Stored information corrupted")
        else:
            obs = Object.GetSelected()
            if len(obs)==0:
                Draw.PupMenu("Error%t|No object selected")
            elif obs[0].type!='Mesh':
                Draw.PupMenu("Error%t|Selected object isn't a mesh")
            else:
                me = Mesh.Get(obs[0].getData(True,True))
                editmode = False
                if Window.EditMode():
                    editmode = True
                    Window.EditMode(0)
        
                for i in stored:
                    me.verts[i[0]].co = i[1]
                    print me.verts[i[0]].co,i[1]
                me.update()
        
                if editmode:
                    Window.EditMode(1)
    else:
        Draw.PupMenu("Error%t|No stored information found")


choice = Draw.PupMenu("Menu%t|Store location|Retrieve location")
if choice == 1:
    Store()
elif choice == 2:
    Retrieve()
  • Select the vertices you wish to store the position of
  • Run the script and chose ‘store location’
  • When you wish to retrieve the location again, run the script once more and pick the ‘retrieve location’ option

Yes your right shape keys would not do what I need, Thanks for the script, Ill try it in a lil bit, I appreciate it.

Thanks alot crouch, that was exactly what I needed, and the script works great. This is going to save me a lot of time.