feat(printer): 新增局域网发送3MF至A1打印机功能
This commit is contained in:
@@ -19,6 +19,7 @@ from .core import (
|
||||
list_swap_gcode_files,
|
||||
)
|
||||
from .paths import default_patch_config_path, default_swap_gcode_dir
|
||||
from .printer import PrinterConfig, send_to_printer
|
||||
|
||||
|
||||
def parse_item(values: list[str]) -> PlateJob:
|
||||
@@ -90,6 +91,21 @@ def build_command(args: argparse.Namespace) -> int:
|
||||
print(f"源文件打印时间:{int(result.total_prediction_seconds)} 秒")
|
||||
if result.total_weight_grams is not None:
|
||||
print(f"源文件耗材重量:{result.total_weight_grams:.2f} g")
|
||||
if args.send_to_printer:
|
||||
config = PrinterConfig(
|
||||
ip=args.printer_ip,
|
||||
access_code=args.printer_access_code,
|
||||
serial=args.printer_serial,
|
||||
)
|
||||
try:
|
||||
send_to_printer(result.output_3mf, config)
|
||||
print(f"已发送至打印机:{result.output_3mf}")
|
||||
except ImportError:
|
||||
print("错误:未安装 bambulabs_api,请执行 pip install bambulabs_api", file=sys.stderr)
|
||||
return 1
|
||||
except Exception as exc:
|
||||
print(f"发送至打印机失败:{exc}", file=sys.stderr)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
@@ -156,6 +172,11 @@ def create_parser() -> argparse.ArgumentParser:
|
||||
build.add_argument("--zip-level", type=int, choices=range(1, 10), default=DEFAULT_ZIP_COMPRESS_LEVEL, metavar="1-9", help="输出 3MF 的 zlib-ng Deflate 压缩级别。默认值:7。")
|
||||
build.add_argument("--no-preview-label", action="store_true", help="不重写预览图标签/合成图。")
|
||||
build.add_argument("--no-gcode-patches", action="store_true", help=f"不应用来自 {default_patch_config_path()} 的可编辑补丁。")
|
||||
# 发送至打印机
|
||||
build.add_argument("--send-to-printer", action="store_true", help="构建后将 3MF 发送至打印机并开始打印。")
|
||||
build.add_argument("--printer-ip", default="", help="打印机 IP 地址(配合 --send-to-printer 使用)。")
|
||||
build.add_argument("--printer-access-code", default="", help="打印机访问码(配合 --send-to-printer 使用)。")
|
||||
build.add_argument("--printer-serial", default="", help="打印机序列号(配合 --send-to-printer 使用)。")
|
||||
# 绑定命令处理函数
|
||||
build.set_defaults(func=build_command)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user