Remove doubles before export I use blender along with Unity. My .blend file sits in unity project directory and each time I make a change to the .blend file, unity refrshes the scene and loads that file.

I would love to have a option to call remove doubles just before that .blend file is read by unity. I know modifiers are aplied during that unity export/read, but i could not find appropriate modifier for that task.

Is there a way to call remove doubles by a script or something like that, before each time unity exports/reads that .blend file ?
Running this script will remove doubles on the currently selected mesh and export the file with a filename appended with -unity

You can then set unity to read the -unity blend and run the script instead of save.

import bpy
newfilename = bpy.context.blend_data.filepath.replace(".blend","-unity.blend")
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.remove_doubles()
bpy.ops.wm.save_as_mainfile(copy=True, filepath=newfilename)