diff --git a/.gitignore b/.gitignore index b7d50d5..9b25fae 100644 --- a/.gitignore +++ b/.gitignore @@ -168,3 +168,4 @@ cython_debug/ *.ipynb *.3mf +*.gcode diff --git a/bambulabs_api/client.py b/bambulabs_api/client.py index fe97f97..aba7168 100644 --- a/bambulabs_api/client.py +++ b/bambulabs_api/client.py @@ -301,7 +301,7 @@ def upload_file(self, file: BinaryIO, filename: str = "ftp_upload.gcode") -> str return "No file uploaded." def start_print(self, filename: str, - plate_number: int, + plate_number: int | str, use_ams: bool = True, ams_mapping: list[int] = [0], skip_objects: list[int] | None = None, @@ -313,8 +313,9 @@ def start_print(self, filename: str, ---------- filename : str The name of the file to be printed. - plate_number : int - The plate number of the file to be printed. + plate_number : (int | str) + The plate number of the file to be printed (assuming the 3mf file + is created with Bambustudio/Orcaslicer). Or the path as a string. use_ams : bool, optional Whether to use the AMS system, by default True. ams_mapping : list[int], optional @@ -714,3 +715,12 @@ def print_error_code(self) -> int: int: error code (0 if normal) """ return self.mqtt_client.print_error_code() + + def print_type(self) -> str: + """ + Get what type of print the current printing file is from (cloud, local) + + Returns: + str: print type + """ + return self.mqtt_client.print_type() diff --git a/bambulabs_api/mqtt_client.py b/bambulabs_api/mqtt_client.py index b9c88d6..f5c61e8 100644 --- a/bambulabs_api/mqtt_client.py +++ b/bambulabs_api/mqtt_client.py @@ -333,7 +333,7 @@ def get_light_state(self) -> str: return light_report[0].get("mode", "unknown") def start_print_3mf(self, filename: str, - plate_number: int, + plate_number: int | str, use_ams: bool = True, ams_mapping: list[int] = [0], skip_objects: list[int] | None = None, @@ -356,12 +356,16 @@ def start_print_3mf(self, filename: str, if skip_objects is not None and not skip_objects: skip_objects = None + if isinstance(plate_number, int): + plate_location = f"Metadata/plate_{int(plate_number)}.gcode" + else: + plate_location = plate_number return self.__publish_command( { "print": { "command": "project_file", - "param": f"Metadata/plate_{int(plate_number)}.gcode", + "param": plate_location, "file": filename, "bed_leveling": True, "bed_type": "textured_plate", @@ -875,3 +879,12 @@ def print_error_code(self) -> int: int: error code (0 if normal) """ return int(self.__get("print_error", 0)) + + def print_type(self) -> str: + """ + Get what type of print the current printing file is from (cloud, local) + + Returns: + str: print type + """ + return self.__get("print_type") diff --git a/examples/print/print_gcode.py b/examples/print/print_gcode.py index 91135ea..43a03b8 100644 --- a/examples/print/print_gcode.py +++ b/examples/print/print_gcode.py @@ -14,6 +14,7 @@ # ============================================================ env = os.getenv("env", "debug") +plate = os.getenv("plate", "true").lower() == "true" def create_zip_archive_in_memory( @@ -55,14 +56,27 @@ def create_zip_archive_in_memory( with open(INPUT_FILE_PATH, "r") as file: gcode = file.read() - gcode_location = "Metadata/plate_1.gcode" - io_file = create_zip_archive_in_memory(gcode, gcode_location) - if file: - result = printer.upload_file(io_file, UPLOAD_FILE_NAME) - if "226" not in result: - print("Error Uploading File to Printer") - - else: - print("Done Uploading/Sending Start Print Command") - printer.start_print(UPLOAD_FILE_NAME, 1) - print("Start Print Command Sent") + if plate: + gcode_location = "Metadata/plate_1.gcode" + io_file = create_zip_archive_in_memory(gcode, gcode_location) + if file: + result = printer.upload_file(io_file, UPLOAD_FILE_NAME) + if "226" not in result: + print("Error Uploading File to Printer") + + else: + print("Done Uploading/Sending Start Print Command") + printer.start_print(UPLOAD_FILE_NAME, 1) + print("Start Print Command Sent") + else: + gcode_location = INPUT_FILE_PATH + io_file = create_zip_archive_in_memory(gcode, gcode_location) + if file: + result = printer.upload_file(io_file, UPLOAD_FILE_NAME) + if "226" not in result: + print("Error Uploading File to Printer") + + else: + print("Done Uploading/Sending Start Print Command") + printer.start_print(UPLOAD_FILE_NAME, gcode_location) + print("Start Print Command Sent") diff --git a/pyproject.toml b/pyproject.toml index 0306956..d754c8d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "bambulabs_api" -version = "2.5.10" +version = "2.5.11" authors = [ { name="Chris Ioannidis", email="chris.ioannidis23@imperial.ac.uk" }, { name="Haotian Wu", email="64962148+ohmdelta@users.noreply.github.com"}