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"

    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():

def unregister():

if __name__ == "__main__":

    # test call

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)

  • $\begingroup$ Yeah, this might be the correct answer. But this ends up in the following error: Cannot open file ~/untitled0012.blend@ for writing: No such file or directory. I don't know why there is a @ symbol in the error message, but the filepath is without it. Maybe blender has a problem with creating a file. I also tried it with open() command and it ended in a FileNotFoundException. $\endgroup$ – Miguellissimo Apr 15 '14 at 19:43
  • 2
    $\begingroup$ Try using an absolute path. Have a look at the python docs $\endgroup$ – pink vertex Apr 16 '14 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.