0
$\begingroup$

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。

$\endgroup$
7
  • $\begingroup$ Have you tried anything on your own yet? or is this all the code you've managed to write? $\endgroup$
    – Jakemoyo
    Apr 15, 2022 at 11:02
  • $\begingroup$ Thanks for your reply, I can render the current scene using bpy.ops.render.render() but don't know how to render the files in the path. $\endgroup$
    – HenDaSheng
    Apr 15, 2022 at 11:05
  • 1
    $\begingroup$ Does this answer your question? How to set render filepath using blend filename in python $\endgroup$
    – Jakemoyo
    Apr 15, 2022 at 11:09
  • $\begingroup$ I tried googling 'blender render from file path' and this was the first result. Make sure you try to do a minimum of research on the subject before asking questions, that way we can make sure there's not 50 of the same question clogging up the forum unneccessarily. If you try this and still run into issues, and can't find answer to those issues then come back and post again with a more specific issue. $\endgroup$
    – Jakemoyo
    Apr 15, 2022 at 11:12
  • 1
    $\begingroup$ @jakemoyo Thank for your help! $\endgroup$
    – HenDaSheng
    Apr 19, 2022 at 7:15

1 Answer 1

0
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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? $\endgroup$
    – HenDaSheng
    Apr 19, 2022 at 7:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .