Skip to content

upate docs for Formlabs Local API 0.9.0 release #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2025
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Python code related to using Formlabs' local and web APIs.

## Python library installation:

First, have Python 3.8 or higher installed and available on your path.
First, have Python 3.9 or higher installed and available on your path.
We recommend installing the Python package in a [Python virtual environment](https://docs.python.org/3/library/venv.html) during testing.

```
Expand Down
23 changes: 12 additions & 11 deletions examples/batching-minimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def create_scene():
},
)
response.raise_for_status()
return response.json()
return response.json()["id"]


parser = argparse.ArgumentParser(description="Process a folder path.")
Expand All @@ -60,6 +60,7 @@ def create_scene():
print(files_to_batch)
current_batch = 1
models_in_current_batch = []
scene_id = None
CSV_RESULT_FILENAME = os.path.join(directory_path, "summary.csv")

pathToPreformServer = None
Expand Down Expand Up @@ -88,12 +89,12 @@ def create_scene():
csvwriter.writerow(["Batch Number", "Batch Print Filename", "Model Source Filename"])

def save_batch_form():
global current_batch, models_in_current_batch
global current_batch, models_in_current_batch, scene_id
form_file_name = f"batch_{current_batch}.form"
save_path = os.path.join(directory_path, form_file_name)
save_form_response = requests.request(
"POST",
"http://localhost:44388/scene/save-form/",
f"http://localhost:44388/scene/{scene_id}/save-form/",
json={
"file": save_path,
},
Expand All @@ -109,21 +110,21 @@ def save_batch_form():
print(f"Uploading batch to {args.upload_to}")
print_response = requests.request(
"POST",
"http://localhost:44388/scene/print/",
f"http://localhost:44388/scene/{scene_id}/print/",
json={
"printer": args.upload_to,
"job_name": form_file_name,
},
)
print_response.raise_for_status()

create_scene()
scene_id = create_scene()
while len(files_to_batch) > 0:
next_file = files_to_batch.pop()
print(f"Importing {next_file}")
import_model_response = requests.request(
"POST",
"http://localhost:44388/scene/import-model/",
f"http://localhost:44388/scene/{scene_id}/import-model/",
json={
"file": os.path.join(directory_path, next_file),
},
Expand All @@ -139,15 +140,15 @@ def save_batch_form():
auto_orient_params["tilt"] = 0
auto_orient_response = requests.request(
"POST",
"http://localhost:44388/scene/auto-orient/",
f"http://localhost:44388/scene/{scene_id}/auto-orient/",
json=auto_orient_params,
)
auto_orient_response.raise_for_status()
if args.auto_support:
print(f"Auto supporting {new_model_id}")
auto_support_response = requests.request(
"POST",
"http://localhost:44388/scene/auto-support/",
f"http://localhost:44388/scene/{scene_id}/auto-support/",
json={
"models": [new_model_id],
},
Expand All @@ -156,7 +157,7 @@ def save_batch_form():
print(f"Auto layouting all")
layout_response = requests.request(
"POST",
"http://localhost:44388/scene/auto-layout/",
f"http://localhost:44388/scene/{scene_id}/auto-layout/",
json={
"models": "ALL",
},
Expand All @@ -166,13 +167,13 @@ def save_batch_form():
model_data = models_in_current_batch.pop()
delete_response = requests.request(
"DELETE",
f"http://localhost:44388/scene/models/{str(model_data['model_id'])}/",
f"http://localhost:44388/scene/{scene_id}/models/{str(model_data['model_id'])}/",
)
delete_response.raise_for_status()
files_to_batch.append(model_data["file_name"])
save_batch_form()
print("Clearing scene")
create_scene()
scene_id = create_scene()

if len(models_in_current_batch) > 0:
save_batch_form()
9 changes: 5 additions & 4 deletions examples/batching.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def list_files_in_directory(directory_path):
]

def create_scene(preform):
return preform.api.create_scene(SceneTypeModel(Manual(
return preform.api.create_default_scene(SceneTypeModel(Manual(
machine_type="FORM-4-0",
material_code="FLGPGR05",
layer_thickness_mm=ManualLayerThicknessMm("0.1"),
Expand Down Expand Up @@ -89,7 +89,7 @@ def save_batch_form():
global current_batch, models_in_current_batch
form_file_name = f"batch_{current_batch}.form"
save_path = os.path.join(directory_path, form_file_name)
preform.api.save_form_file(LoadFormFileRequest(file=save_path))
preform.api.save_form_file("default", LoadFormFileRequest(file=save_path))
print(f"Saving batch {current_batch} to {save_path}")
for i, model in enumerate(models_in_current_batch):
print(f"{i+1}. {model['file_name']}")
Expand All @@ -104,7 +104,7 @@ def save_batch_form():
while len(files_to_batch) > 0:
next_file = files_to_batch.pop()
print(f"Importing {next_file}")
new_model = preform.api.import_model({"file": os.path.join(directory_path, next_file)})
new_model = preform.api.import_model("default", {"file": os.path.join(directory_path, next_file)})
new_model_id = new_model.id
models_in_current_batch.append({"model_id": new_model_id, "file_name": next_file})
if args.auto_orient:
Expand All @@ -119,12 +119,13 @@ def save_batch_form():
print(f"Auto layouting all")
try:
preform.api.auto_layout_with_http_info(
"default",
AutoLayoutRequest(models=ModelsSelectionModel("ALL"))
)
except formlabs.exceptions.ApiException as e:
print("Not all models can fit, removing model")
model_data = models_in_current_batch.pop()
preform.api.delete_model(str(model_data["model_id"]))
preform.api.delete_model(str(model_data["model_id"]), "default")
files_to_batch.append(model_data["file_name"])
save_batch_form()
print("Clearing scene")
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def hello_server():
else:
print("Unsupported platform")
sys.exit(1)
with formlabs.PreFormApi.start_or_connect_to_preform_server(pathToPreformServer=pathToPreformServer) as preform:
with formlabs.PreFormApi.start_preform_server(pathToPreformServer=pathToPreformServer) as preform:
preform.api.create_scene(SceneTypeModel(Manual(
machine_type="FORM-4-0",
material_code="FLRG1011",
Expand Down
Loading