I have multiple object in blender. There is an object ,lets called it "Obj1" ,which is the object I have to edit ,it does not allow to add/delete vertices ,faces ,edges to it,(require keeping the vertex's ordinal number of that object), all others transform (rotate ,scale ,move) are fine. (but of course we can freely do anything with others object)

I want to save the location(x,y,z) of selected vertices of that object ("Obj1") into a file ,so that I can restore those vertices back to location when I need (only "restore" the location of saved vertices, all others vertices are not affected). The ordinal number of vertices number of "Obj1" will never change during my edit,so i think we can use save location of vertex with its ordinal number like this :

[vertex ordinal number]-[x]-[y]-[z]

i get a hint , but i am still beginer in coding python (i have just started learning when encounter this problem) , so i greatly appreciate if someone can help me to make it complete


import bpy

obj = bpy.context.object
for v in obj.data.vertices:
    print("index=" + str(v.index) + " loc=" + str(v.co))

This gets the location of vertices in local space.

To write in a file, use normal Python IO routines.


  • $\begingroup$ ok, now is clearer, so I deleted my answer, since is now certainly completely unrelated... maybe also add the practical reason, an example, of why you need to do so, it could give more hints to a possibile solution. $\endgroup$
    – m.ardito
    Nov 18, 2015 at 8:28
  • $\begingroup$ I need to do that because while editing model, there are manysteps , so I save each step to a blender file for example like this. Step1 : save as file 1.blend : edit the leg for fit the trouser. Step2 : save as file 2.blend : edit the arm of file 1 (continue of file1). then I put in to test ,if I feel not satisfied with the leg that I have edited in step1 (file1). , i can revert the leg back to the original one (before i edited in step1 (file1) but still keep the arm that I edited in step2 Thanks again $\endgroup$
    – mtrcol
    Nov 19, 2015 at 3:50
  • $\begingroup$ you should perhaps experiment with shape keys and vertex groups -- it seems to me that the functionality you're after is already built in and you don't need to save separate files to experiment on variations of meshes. (see links) $\endgroup$
    – zeffii
    Nov 19, 2015 at 8:54
  • $\begingroup$ Thanks zeffii ,i already knew about them , i use mask modifier to display the original mesh too,but i have to alter the vertices many times to test the animation, and i think its better if i can save and load the vertices :) $\endgroup$
    – mtrcol
    Nov 19, 2015 at 10:39

1 Answer 1


If Vertex Groups and Shape Keys don't address the problem, it is straight-forward to make a script. I'm not sure I understand your constraints but they seem to be:

  • locations of verts of the initial object are stored
  • indices and vert-count are unchanged
  • coordinates can change.
  • you want to be able to restore those verts in your modified object which are currently selected.

Rather than writing a script + ui for this, i'd first explore the code needed. I'm going to assume you aren't talking about thousands of vertices, if you do need larger meshes then optimization would help speed up the 'overwrite'

As usual many approaches are possible, i'd start with the one that requires least effort to understand and write. Start a new .blend with a dummy object to represent a simplified version of the objects you are trying to work with in your production files. Get a hang of whether this method works for you or not.

The clone mesh

This makes a mesh clone of your original object, gives it a fake user. The fake user flag tells blender not to delete the Mesh when it has no direct users.


import bpy

mode_set = bpy.ops.object.mode_set

ob = bpy.context.active_object
mode_set(mode = 'OBJECT')

clone_mesh = ob.data.copy()
clone_mesh.name = ob.name + '_clone'
clone_mesh.use_fake_user = True

mode_set(mode = 'EDIT')  # place originally active object back to edit

This finds the clone and updates the active_object's selected vertices using the previously cloned mesh data.


import bpy

meshes = bpy.data.meshes
mode_set = bpy.ops.object.mode_set

ob = bpy.context.active_object
mode_set(mode = 'OBJECT') # updates the list of selected verts too

clone_mesh = meshes.get(ob.name + '_clone')
clone_verts = clone_mesh.vertices

for v in ob.data.vertices:
    if v.select:
        v.co = clone_verts[v.index].co

mode_set(mode = 'EDIT')

Usage without UI:

  • The top one you run once, at the start. While your base object is active.
  • The second script is what you run whenever you want to restore the selected vertices.

enter image description here

Ui version

Here's a small UI version of that script. You can either pick a directory using the selector or paste it in manually. Even if you pick a file from the FileBrowser it will strip the path to just be a Folder/Directory.

It appears in the Misc panel:

enter image description here

if you have the Suzanne Object selected it can clone the object and make a hidden mesh, or look in the directory provided for a Suzanne.json, which it can load as the clone mesh.

  • clone: Clones the Object's mesh as a hidden mesh called <object_name>_clone
  • restore: Restores the locations of the vertices currently selected
  • changed: Selects only those vertices which changed their locations
  • import: Tries to import a hidden mesh. The currently selected object's name is used to find the json: directory/<object_name>.json
  • export: Makes a <object_name>.json in the directory pointed at.
  • $\begingroup$ Thank you very much ,zeffii, i 'll try it .you made my day :) $\endgroup$
    – mtrcol
    Nov 20, 2015 at 10:27
  • $\begingroup$ Hi again , zefffii Thank you very much ,i tested and i see your script works great ,speeds are awesome too :) sorry for asking but is it possible to restore the edges too ? i mean if i rotated the edge (by using Mesh => Faces => Rotate Edges) , this script can't restore the edge to the original if it takes much time of yours, then i would be satisfied with this version :D Thank you very much $\endgroup$
    – mtrcol
    Nov 20, 2015 at 18:29
  • $\begingroup$ ah i think it won't lose vertex index order because i have already rotated the edge and it still works fine (if the vertex index change ,the compiled model will have problem,while it still works fine) i don't know how long it takes a beginner like me can add a feature like that to your script , but i'll try anyway thank you :) $\endgroup$
    – mtrcol
    Nov 20, 2015 at 18:36
  • $\begingroup$ please delete some comments here so we can keep this question tidy. also see github.com/zeffii/MeshCloneRestore/issues/1 i'll make it an add-on. $\endgroup$
    – zeffii
    Dec 12, 2015 at 13:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .