0

I can pass Command Line Rendering Render .blend files based on paths.

blender -b "file path" -a

Next, I want to try doing it via bpy, I can render the current scene via bpy.ops.render.render(), but how do I get Blender Python to render the .blend file in the path?

import bpy

file_path = '/BlenderRenderScript_Test/model/02.blend'

Thank you for your help。

HenDaSheng
  • 53
  • 5

1 Answers1

0

You are asking, in effect, "How can I open a new blend file from the currently running Blender instance and then continue running commands from the same script?"

The answer is "You can't". You can do the first part, opening an new blend file using

bpy.ops.wm.open_mainfile(filepath="file path")

but as soon as you do that your current script will stop running and Blender will do exactly what it would have done if you hit the "Open" entry in the File menu: start over with the new file.

Marty Fouts
  • 33,070
  • 10
  • 35
  • 79
  • Thanks for you help!I wrote a python script that iterates over multiple blender files and executes render(blender -b "file path" -a) commands in sequence. But this method is not friendly to people who are not familiar with programming, so I want to traverse multiple blender files through bpy and execute related commands in sequence.

    my plan:

    1. Internal functions of Blender;
    2. Create an easy-to-operate GUI interface;

    Excuse me, does bpy support the practice of traversing multiple files and executing related commands in sequence?

    – HenDaSheng Apr 19 '22 at 07:42