[英]How to translate command-line into python code
I am currently working with python and I have some real trouble with the syntax.我目前正在使用 python 并且我在语法上遇到了一些真正的问题。 I wanted to include a Cura command-line into my script but I do not know how to actually parse the line so that the command will be executed out of my Blender Script.
我想在我的脚本中包含一个 Cura 命令行,但我不知道如何实际解析该行,以便从我的 Blender 脚本中执行该命令。 My code is the following and I really do not know if this is even valid:
我的代码如下,我真的不知道这是否有效:
def main(context):
blend_file_path = bpy.data.filepath
directory = os.path.dirname(blend_file_path)
target_file = os.path.join(directory,bpy.path.basename(bpy.context.blend_data.filepath) +'.stl')
bpy.ops.export_mesh.stl(filepath=target_file)
cevar = 'CuraEngine slice -j "C:\\Programme\\Ultimaker Cura 4.5\\resources\\definitions\\fdmprinter.def.json"' +' -l ' + directory + bpy.path.basename(bpy.context.blend_data.filepath) +'.stl +o '+ directory + bpy.path.basename(bpy.context.blend_data.filepath) +'.gcode'
os.system(cevar)
Use this code使用此代码
import subprocess
cmd_args = [
"CuraEngine",
"slice",
"-j",
"C:\\Programme\\Ultimaker Cura 4.5\\resources\\definitions\\fdmprinter.def.json",
"-l",
f"{os.path.join(directory,bpy.path.basename(bpy.context.blend_data.filepath))}.stl",
"+o",
f"{os.path.join(directory, bpy.path.basename(bpy.context.blend_data.filepath))}.gcode",
]
output = subprocess.Popen(cmd_args, stdout=subprocess.PIPE).communicate()[0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.