【问题标题】:Run blender from command line with custom startup .blend file使用自定义启动 .blend 文件从命令行运行搅拌机
【发布时间】:2021-01-08 20:00:21
【问题描述】:

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

blender --startup-file my_file.blend

我不想做blender my_file.blend,因为那样我可能会不小心保存文件并覆盖my_file.blend,它应该是一个模板而不是一个可编辑的文件。如果我尝试保存,我希望得到选择文件名的提示。我怎样才能从命令行完成呢?

【问题讨论】:

    标签: blender


    【解决方案1】:

    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】:

      运行

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

      并将其放入 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

      【讨论】:

      • 我的目标是避免预先指定像“my_new_file.blend”这样的文件名,而是让用户在决定保存文件时按 ctrl + s。
      猜你喜欢
      • 2014-06-07
      • 2014-01-15
      • 1970-01-01
      • 2015-09-29
      • 1970-01-01
      • 2016-05-24
      • 2016-07-21
      • 2017-07-08
      • 1970-01-01
      相关资源
      最近更新 更多