Saving base mesh between iterations of script?

I am writing a script to modify a mesh, at each frame, but I want to modify it from it’s base values as though starting from frame zero through each iteration of the script. How do I save the mesh on the first iteration, modify the visible mesh, then reuse the saved mesh as the base.

I am new to python and probably wondering how to selectively execute portions of a script. Thus if my saved mesh already exists don’t save it again.

Duplicate the mesh, then either store the object in a non-visible layer or scene:


from Blender import Object
import bpy

scn = bpy.data.scenes.active

Object.Duplicate(mesh = 1) #Duplicates the active object
dupedOb = scn.objects.active

######Move to new layer or new scene

When you want to alter the object:


from Blender import Object
import bpy

scn = bpy.data.scenes.active

Object.Duplicate(mesh = 1) #Duplicates the active object
dupedOb = scn.objects.active

dupMesh = dupedOb.getData(mesh = True)

# Start altering dupMesh

To make sure we only have one original copy of the mesh hanging around, that retains across script calls (I assume your using scriptlinks, if not give some more detail):


from Blender import Object, Registry
 import bpy
 
 scn = bpy.data.scenes.active
 
dupFlag = 0
regD = Registry.GetKey('TestScript', True)
if regD:
     try:
          dupFlag = regD['dupFlag']
     except:
          regD = {}
          regD['dupFlag'] = 1
          Registry.SetKey('TestScript', regD, True)

if not dupFlag:
     # Make your base mesh active
     Object.Duplicate(mesh = 1) #Duplicates the active object
     
     regD = {}
     regD['dupFlag'] = 1
     Registry.SetKey('TestScript', regD, True)

Object.Duplicate(mesh = 1) #Get another copy for us to work on
dupedOb = scn.objects.active
dupMesh = dupedOb.getData(mesh = True)
# Start altering dupMesh

Let us know if you need any more help (also I wrote the code without testing it :o, so you may need to twiddle with some things to get it to how you like it).

You understood what I meant perfectly and I will try out that routine.