代码之家  ›  专栏  ›  技术社区  ›  Mei Zhang

通过自定义启动从命令行运行blender。混合文件

  •  0
  • Mei Zhang  · 技术社区  · 6 年前

    我知道我可以使用更改默认启动文件 File/Defaults/Save Startup File . 我不想更改默认的启动文件,而是从命令行使用自定义 .blend 启动文件,类似于:

    blender --startup-file my_file.blend
    

    blender my_file.blend 因为这样我会意外地保存文件并覆盖 my_file.blend ,它应该是一个模板,而不是一个可编辑的文件。如果我试图保存,我想得到选择文件名的提示。如何从命令行实现这一点?

    0 回复  |  直到 6 年前
        1
  •  0
  •   unwave    5 年前

    https://docs.blender.org/api/current/bpy.ops.wm.html#bpy.ops.wm.read_homefile

    blender --python-expr "import bpy; bpy.ops.wm.read_homefile(filepath=r'my_file.blend')"
    

    或者作为脚本:

    import bpy
    import subprocess
    
    path = r"D:\Desktop\test.blend"
    
    script = "\n".join([
            "import bpy",
            f"bpy.ops.wm.read_homefile(filepath=r\"{path}\")"
        ])
        
    subprocess.Popen([bpy.app.binary_path, "--python-expr", script])
    
    
        2
  •  -1
  •   Shantanu Aryan    6 年前

    blender "my_file.blend" --python "my_script.py"
    

    把这个写进我的剧本里。派克

    import bpy
    bpy.ops.wm.save_as_mainfile(filepath="my_new_file.blend", compress=False)
    

    https://docs.blender.org/manual/en/latest/advanced/command_line/arguments.html#python-options https://docs.blender.org/api/current/bpy.ops.wm.html#bpy.ops.wm.save_as_mainfile