Save file inside an operator I have written a simple operator to save the current blender file, but when the operator reaches the save function I get an error. I used the bpy.ops.save_as_mainfile() function for saving a scene, but I don't know if it's the right one to choose.

The console outputs this error:

TypeError: 'BPyOpsSubMod' object is not callable
location: /opt/blender/2.70/scripts/modules/bpy/ops.py:188


Does that mean I cannot call functions from bpy.ops?

My script is the the following:

import bpy
class SaveOperator(bpy.types.Operator):
    bl_idname = "object.save_op"
    bl_label = "Save scene"

    @classmethod
    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):

        # build file name stuff
        # ...

        bpy.ops.save_as_mainfile('~/' + new_file_name)

        return {'FINISHED'}


def register():
    bpy.utils.register_class(SaveOperator)


def unregister():
    bpy.utils.unregister_class(SaveOperator)


if __name__ == "__main__":
    register()

    # test call
    bpy.ops.object.save_op()
You have to pass your parameters as keyword arguments. See api docs

The correct call should be bpy.ops.wm.save_as_mainfile(filepath=your_path)