Opening .blend files using the Blender Python API

I am trying to create an automatic build system for Blender 2.73 that reads XML files with many paths, opens the files one by one, and then displays them.

I use the following code to open:

bpy.ops.wm.open_mainfile("file_path")

My problem is that I get the following error:

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "<BLENDER_PATH>/scripts/modules/bpy/ops.py", line 186, in __call__
    ret = op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
TypeError: Calling operator "bpy.ops.wm.open_mainfile" error, expected a string enum in ('INVOKE_DEFAULT', 'INVOKE_REGION_WIN', 'INVOKE_REGION_CHANNELS', 'INVOKE_REGION_PREVIEW', 'INVOKE_AREA', 'INVOKE_SCREEN', 'EXEC_DEFAULT', 'EXEC_REGION_WIN', 'EXEC_REGION_CHANNELS', 'EXEC_REGION_PREVIE)
+4
source share
1 answer

The problem with your operator call is that it does not accept positional arguments, you need to specify each argument -

bpy.ops.wm.open_mainfile(filepath="file_path")

Blender allows you to open one open file at the same time, when you open another mix file, existing data fails, this usually includes the script that you use.

bpy.app.handlers, , blend. blend.

import bpy
from bpy.app.handlers import persistent

@persistent
def load_handler(dummy):
    print("Load Handler:", bpy.data.filepath)

bpy.app.handlers.load_post.append(load_handler)

, ,

blender --background thefile.blend -a

, blend.

python script , blend . .

+10

All Articles