Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,4 @@ cython_debug/
*.ipynb

*.3mf
*.gcode
16 changes: 13 additions & 3 deletions bambulabs_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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()
17 changes: 15 additions & 2 deletions bambulabs_api/mqtt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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")
36 changes: 25 additions & 11 deletions examples/print/print_gcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# ============================================================

env = os.getenv("env", "debug")
plate = os.getenv("plate", "true").lower() == "true"


def create_zip_archive_in_memory(
Expand Down Expand Up @@ -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")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]" },
{ name="Haotian Wu", email="[email protected]"}
Expand Down