Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I want to generate a computerized build system for Blender 2.73 which shows XML files with lots of paths, opens the files one by another, and then distributes them.

I am working with the following code in order 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)

1 Answer

0 votes
by (108k points)

The issue is with your executive call is that it doesn't accept positional arguments, you need to name each argument -

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

Kindly be informed that the Blender in python can only allow opening one file at a time, if you open another blend file, then the existing data is washed out of ram, this usually includes the script you are running.

If you refer to the bpy.app.handlers, you can set up a handler to be persistent, in that it will remain in memory after loading a new blend file. This can let you run your code after the new blend file is opened.

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

Browse Categories

...