在命令行中使用 subprocess.Popen() 执行的脚本打印“导出完成”后立即关闭 Blender

问题描述

在下面的代码中,Blender2.79 用一个项目打开,从命令行连续执行两个 Python 脚本。最后一个 Python 脚本在完成后输出字符串 "export finished in xx.xxxx sec."。如何捕获此输出并相应地结束子流程(Blender)?这是我的代码

if __name__ == '__main__':
# blender project.blend --python main.py --python fbxexport.py
cmd = ["D:\\Blender279\\blender.exe","D:\\...\\project.blend","--python","D:\\...\\Scripts\\Main.py","D:\\...\\Python_FBX_Export\\fbxexportanim.py"]
p1 = subprocess.Popen(cmd)
sstdout,sstdErr = p1.communicate()
# i want to do something like...
# if "export finished" in str(sstdout): # if fbxexportanim is finished
#    p1.kill()
# ... but p1.communicate() waits until end-of-file is reached,that's why this does not work

编辑

这是 fbxexportanim.py 脚本:

import bpy

# for anim
bpy.ops.export_scene.fbx(filepath="D:\\...\\fbx\\anim.fbx",use_selection=True,apply_unit_scale=0.01,object_types={'OTHER','MESH','ARMATURE'},mesh_smooth_type='FACE',add_leaf_bones=False,use_armature_deform_only=True,bake_anim_use_nla_strips=False,bake_anim_use_all_actions=False)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)