Saving via the API?

So I am running a script in UI-less mode:

blender -b -P script.py

The script is generating a lot of geometry and I want to save that to a .blend file.
I tried using:

bpy.ops.wm.save_as_mainfile("/home/user/foo.blend")

and

bpy.ops.wm.save_mainfile("/home/user/foo.blend")

at the end of the script to save the file, without much success.

I searched the API docs and the web couldn’t find any other ops or commands that can do this… how do people save files when running background scripts?

Thanks!

i’m on windows and it works for me:

C:\Program Files\Blender Foundation\Blender>blender -P C:\Users\CoDEmanX\Desktop
<b>saveme.py -b C:\Users\CoDEmanX\Desktop\removeme.blend -P C:\Users\CoDEmanX\Desk
top<b>saveme2.py

found bundled python: C:\Program Files\Blender Foundation\Blender\2.64\python
Total files 0|Changed 0|Failed 0
read blend: C:\Users\CoDEmanX\Desktop\removeme.blend
Total files 0|Changed 0|Failed 0
Total files 0|Changed 0|Failed 0

Blender quit

I use absolute paths for blend and scripts, otherwise it won’t work (unless i run from the dir where they are in and use absolute path for blender executable instead)

The py scripts are:

import bpy
bpy.ops.wm.save_as_mainfile(filepath="D:\\pysaved.blend")

import bpy
bpy.ops.wm.save_as_mainfile(filepath="D:\\pysaved2.blend")

And both files are created at given location.

I didn’t write the parameter name:
“filepath=”

It works now. Thank you for your time.

oh yeah, you can’t use positional arguments on operators, as they will interpret this as override or something