help - backing up and restoring mesh

hi all,

I dunno if there may be a better way to do this, I’m trying to get it coding two scripts. Save script seems to work ok, but after changing a few verts and running load script the mesh never gets to it’s original state.

If anyone may know what I’m doing wrong please let me know.

http://boostnetwork.net/downloads/scripts.zip

Save Script

``` #!BPY

“”"
Name: ‘F1 Backup coords’
Blender: 242
Group: ‘Export’
Tooltip: ‘’
“”"

import Blender
from Blender import Draw
from Blender.BGL import *
from Blender import Window
import os

#Ex
def SaveProperties(DataFilePath):

print "Creating Data File:",DataFilePath


# Try to create Data File
try:
    DataFile = open(DataFilePath,'w+')    
except:
    print "Error in opening %s" %DataFilePath
    return 0

# Try to get Vertex List
Faces = None
try:
    Verts = Blender.Object.GetSelected()[0].getData().verts
except:
    print  "No object selected"
    return

# Save coors
for x in range(len(Verts)):
    Vert = Verts[x]
    DataFile.write("%f,%f,%f

" % (Vert.co[0],Vert.co[1],Vert.co[2]))

DataFile.close()    
return 1    

#/Ex

SaveProperties(“d:/d/” + Blender.Object.GetSelected()[0].name)

<b>


Load script</b>


#!BPY

“”"
Name: ‘F1 Restore coords’
Blender: 242
Group: ‘Export’
Tooltip: ‘’
“”"

import Blender
from Blender import Draw
from Blender.BGL import *
from Blender import Window
import os

#Ex
def LoadProperties(DataFilePath):

print "Loading Data File: ",DataFilePath


# Try to open Data File
try:
    DataFile = open(DataFilePath)    
except:
    print "Error in opening %s" %DataFilePath
    return 0


# Try to get Vertex List
Verts = None
try:
    Verts = Blender.Object.GetSelected()[0].getData().verts
except:
    print  "No object selected"
    return

# Restore coors
for x in range(len(Verts)):
    Vert = Verts[x]
    vertexData = DataFile.readline()
    vertexCoo = vertexData.split(',')
    
    Vert.co[0] = float(vertexCoo[0])
    Vert.co[1] = float(vertexCoo[1])
    Vert.co[2] = float(vertexCoo[2])

                    
DataFile.close()    
return 1    

#/Ex

LoadProperties(“d:/d/” + Blender.Object.GetSelected()[0].name)

With the CVS version of Blender Iv added a .copy() function to most copyable data types,
So you could just work on a copy.
If you want to store the coords in blender, make a copy and give it a fake user.

me= Blender.Object.GetSelected()[0].getData(mesh=1).copy()
me.fakeUser= True # so blender wont deallocate the mesh that has no users

Another usefull way is to use Meshes PVerts
verts_backup= me.verts[:]

me.verts= verts_backup

With this youll need to recreate the pverts from a file, but thats possible.

The problem in this case may be that your assuming the order of coords stays the same.

thanks cambo, much appreciated :slight_smile: