A Python script to calculate the real cost of a 3D print using slicer filament estimative and fetching actual costs of each spool from the Spoolman API. This tool helps 3D printing enthusiasts and professionals accurately estimate the filament costs for their prints, considering multiple spools and different units of measurement.
- Features
- Prerequisites
- Installation
- Configuration
- Usage
- Example Output
- Contributing
- License
- Acknowledgements
- Exclude Archived Spools: Automatically filters out archived spools from the selection list.
- Multiple Filament Calculation: Supports cost calculation for prints using multiple spools.
- Flexible Units: Accepts filament usage input in grams or meters, with units specified directly in the input (e.g.,
100g
,50m
). - User-Friendly Interaction: Provides detailed prompts and error messages to guide the user.
- Summary Report: Displays a formatted summary of all filaments used and their individual costs at the end.
- Customizable API URL: Reads the Spoolman API URL from the
.env
file or defaults tohttp://localhost:7912
.
- Python 3.6 or higher
-
Clone the Repository
git clone https://github.com/vechiato/filament-cost-calculator.git cd filament-cost-calculator
-
Create a Virtual Environment (Optional but Recommended)
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Required Packages
pip install -r requirements.txt
Note: The
requirements.txt
file should contain:requests python-dotenv
-
Set Up Environment Variables
Create a
.env
file in the project directory to store environment variables such as your Spoolman API URL and API key.touch .env
Add the following to the
.env
file:# Spoolman API URL (default is http://localhost:7912/api/v1 if not set) SPOOLMAN_API_URL=http://your-spoolman-ip:7912/api/v1 # Spoolman API Key (if required) SPOOLMAN_API_KEY=your_api_key_here
- SPOOLMAN_API_URL: Replace
http://your-spoolman-api-url/api/v1
with your actual Spoolman API URL.- If you don't set this variable, the script defaults to
http://localhost:7912/api/v1
.
- If you don't set this variable, the script defaults to
- SPOOLMAN_API_KEY: Replace
your_api_key_here
with your actual Spoolman API key if your API requires authentication.- If your API doesn't require authentication, you can leave this unset.
- SPOOLMAN_API_URL: Replace
Run the script using Python:
python calculate_filament_cost.py
Follow the on-screen prompts to select spools and enter filament usage.
- Spool Selection: Enter the number corresponding to the spool you want to select.
- Filament Usage: Input the amount of filament used with units appended (e.g.,
100g
for grams,50m
for meters). If no unit is specified, the script assumes grams.
- Grams (g): Enter filament usage in grams (e.g.,
100g
or100
). - Meters (m): Enter filament usage in meters (e.g.,
50m
).
-
Select Spools
The script will display a list of available spools:
Available Spools: 1. PLA Red (ID: 1) Price: $16.49 Material: PLA Color: ff0000 2. PLA White (ID: 2) Price: $10.99 Material: PLA Color: ffffff 3. NYLON GREY (ID: 3) Price: $28.99 Material: NYLON Color: 808080 4. PETG BLACK (ID: 4) Price: $15.99 Material: PETG Color: 000000 ...
Enter the number corresponding to the spool you wish to use.
-
Enter Filament Usage
When prompted, enter the amount of filament used with the unit:
Enter filament used for the print (e.g., '100g' or '1.5m'): 100g
-
Add Additional Spools
After each spool, the script will ask if you want to add another spool:
Do you want to add another spool? (y/n): y
-
View Summary
Once you have entered all the spools and filament usage, the script will display a summary:
Summary of Filament Usage: Spool Name Filament Used Unit Cost --------------------------------------------------------------------------- PLA Red 100.34 g 1.65 PLA White 53.21 m 1.74 --------------------------------------------------------------------------- Total Cost: 3.40
Available Spools:
1. PLA Red (ID: 1) Price: $16.49 Material: PLA Color: ff0000
2. PLA White (ID: 2) Price: $10.99 Material: PLA Color: ffffff
3. NYLON GREY (ID: 3) Price: $28.99 Material: NYLON Color: 808080
4. PETG BLACK (ID: 4) Price: $15.99 Material: PETG Color: 000000
...
Select a spool by number: 1
Selected Spool: PLA Red
Spool Cost: $16.49
Remaining Filament Weight: 912.13 grams
Material: PLA, Diameter: 1.75 mm, Density: 1.24 g/cm³
Enter filament used for the print (e.g., '100g' or '1.5m'): 100.34g
Cost for this print: $1.65
Do you want to add another spool? (y/n): y
Select a spool by number: 2
Selected Spool: PLA White
Spool Cost: $10.99
Remaining Filament Weight: 440.00 grams
Material: PLA, Diameter: 1.75 mm, Density: 1.24 g/cm³
Enter filament used for the print (e.g., '100g' or '1.5m'): 53.21m
Cost for this print: $1.74
Do you want to add another spool? (y/n): n
Summary of Filament Usage:
Spool Name Filament Used Unit Cost
---------------------------------------------------------------------------
PLA Red 100.34 g 1.65
PLA White 53.21 m 1.74
---------------------------------------------------------------------------
Total Cost: 3.40
Contributions are welcome! Please follow these steps:
-
Fork the Repository
-
Create a Feature Branch
git checkout -b feature/your-feature-name
-
Commit Your Changes
git commit -am 'Add your feature'
-
Push to the Branch
git push origin feature/your-feature-name
-
Create a Pull Request
This project is licensed under the MIT License.
- Spoolman API: This script utilizes the Spoolman API for fetching spool data. Spoolman API Documentation
This README was created to provide clear instructions and information about the Filament Cost Calculator script. If you have any questions or need further assistance, please feel free to reach out.