Skip to content
Open
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
79 changes: 68 additions & 11 deletions FilamentSamples.scad
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Change For Each Card
BRAND="extrudr";
COLOR="Metallic Grey";
COLOR2="";
TYPE="Biofusion";
TEMP_HOTEND="225";
TEMP_BED="60";
TYPE2="";
TEMP_HOTEND="";
TEMP_BED="";

// Change only if absolutely necessary
COLOR_SIZE=5.5;
Expand Down Expand Up @@ -70,8 +72,10 @@ FONT = "Liberation Sans:style=Bold";
TEXT_X=4.0;
TEXT_Y=39.0;
TEXT_DEPTH=1.5;
//TEXT_TEMP=str(TEMP_HOTEND, "\u00B0\u2013", TEMP_BED, "\u00B0");
TEXT_TEMP=str("N", TEMP_HOTEND, "\u00B0 B", TEMP_BED, "\u00B0");

TEXT_HOTEND_TEMP = str("N", TEMP_HOTEND, "\u00B0");
TEXT_BED_TEMP = str("B", TEMP_BED, "\u00B0");
TEXT_TEMP = (TEMP_HOTEND && TEMP_BED) ? str("N", TEMP_HOTEND, "\u00B0 B", TEMP_BED, "\u00B0") : (TEMP_HOTEND ? TEXT_HOTEND_TEMP : (TEMP_BED ? TEXT_BED_TEMP : ""));
TEXT_FL_TEMP=str(" ", TEMP_HOTEND_FIRST_LAYER, "\u00B0\u2013", TEMP_BED_FIRST_LAYER, "\u00B0");

$fn = 50;
Expand Down Expand Up @@ -129,13 +133,66 @@ module TopInset(Inset_X, Thickness) {
}

module CardInfo() {
Text(16.5, TEXT_TEMP, TEMP_SIZE, 1.1, "right", CARD_LENGTH-TEXT_X+0.2);
Text(24, COLOR, COLOR_SIZE, 1.0);
Text(10, BRAND, BRAND_SIZE, 1.0);
if (SHOW_FIRSTLAYER_TEMP == 1) {
Text(14, TEXT_FL_TEMP, 3, 1.0);

// Temperature text if it was set
if (TEXT_TEMP)
{
Text(16.5, TEXT_TEMP, TEMP_SIZE, 1.1, "right", CARD_LENGTH-TEXT_X+0.2);
}

// Color text
if (COLOR)
{
Text(24, COLOR, COLOR_SIZE, 1.0);
}
if (COLOR2)
{
Text(24, COLOR2, BRAND_SIZE, 1.0, "right", CARD_LENGTH-TEXT_X+0.2);
}

// Brand and type
if (BRAND)
{
if (TYPE && TYPE2) // Brand + 2 type lines
{
Text(16, BRAND, BRAND_SIZE, 1.0);
Text(10, TYPE, TYPE_SIZE, 1.0);
Text(4, TYPE2, TYPE_SIZE, 1.0);
}
else
{
if (TYPE) // Brand + 1 type line
{
Text(10, BRAND, BRAND_SIZE, 1.0);
Text(4, TYPE, TYPE_SIZE, 1.0);
}
else if (TYPE2) // Brand + 1 type line
{
Text(10, BRAND, BRAND_SIZE, 1.0);
Text(4, TYPE2, TYPE_SIZE, 1.0);
}
else // Brand only
{
Text(4, BRAND, BRAND_SIZE, 1.0);
}
}
}
else
{
if (TYPE && TYPE2) // 2 type lines
{
Text(10, TYPE, TYPE_SIZE, 1.0);
Text(4, TYPE2, TYPE_SIZE, 1.0);
}
else if (TYPE) // 1 type line
{
Text(4, TYPE, TYPE_SIZE, 1.0);
}
else if (TYPE2) // 1 type line
{
Text(4, TYPE2, TYPE_SIZE, 1.0);
}
}
Text(4, TYPE, TYPE_SIZE, 1.0);
}

module InfillInfo() {
Expand Down Expand Up @@ -204,4 +261,4 @@ module Card() {
}
}

Card();
Card();
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ Another great method across systems is using VS Code. If you cloned this repo
and open it within VS-Code make sure you have the Python extension installed.
Then you can just edit the .csv right there, open the `gen_saples.py` script and immidiately run it with the play button in the upper right. Of course you still need some version of Python and OpenSCAD installed, Python should be found by VS Code if it is there.

## Sample Fields

The first line in samples.csv is the labels for the columns: "Brand", "Type", "Type2", "Color", "Color2", "Bed Temp", "Hotend Temp". All of the fields are optional and if you leave any of them empty then they will not be added to the sample chip.

This example shows all of the fields:
<img src="docs/example_fields1_scad.png" width="350" hspace="15"/> <img src="docs/example_fields1.png" width="300" hspace="15"/>

1. Color
2. Color2
3. Brand
4. Type
5. Type2
6. Hotend (nozzle) Temp
7. Bed Temp

Any field that is left blank will not be included. This example shows just Color, Brand, Type:
<img src="docs/example_fields2_scad.png" width="350" hspace="15">


## Using the stl-Models

The output will be generated under the `stl`-Folder.
Expand Down
Binary file added docs/example_fields1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/example_fields1_scad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/example_fields2_scad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 59 additions & 22 deletions gen_samples.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env python3

import subprocess
import argparse
import csv
import os
import platform
import subprocess
import traceback

if platform.system() == 'Windows':
OPENSCAD = 'C:\Program Files\OpenSCAD\openscad.exe'
Expand All @@ -12,26 +14,61 @@
else:
OPENSCAD = '/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD'

MYDIR=os.path.dirname(os.path.realpath(__file__))

def gen_samples(file=f"{MYDIR}/samples.csv"):
os.makedirs(f"{MYDIR}/stl", exist_ok=True)
with open(file, '+r') as f:
data = csv.reader(f)

for l in data:
print("Processing:", l)
filename = "stl/" + "_".join(l) + ".stl"
subprocess.run(
[OPENSCAD,
'-o', filename,
'-D', f'BRAND="{l[0]}"',
'-D', f'TYPE="{l[1]}"',
'-D', f'COLOR="{l[2]}"',
'-D', f'TEMP_HOTEND="{l[3]}"',
'-D', f'TEMP_BED="{l[4]}"',
f'{MYDIR}/FilamentSamples.scad',
], check=True)
MYDIR = os.path.dirname(os.path.realpath(__file__))

expected_fields = ("Brand", "Type", "Type2", "Color", "Color2", "Bed Temp", "Hotend Temp")

def gen_samples():
# Ensure output directory exists
output_dir = f"{MYDIR}/{args.output_dir}"
os.makedirs(output_dir, exist_ok=True)

# Open the input file and read line by line
input_filename = f"{MYDIR}/{args.input_file}"
with open(input_filename, 'r', encoding="utf-8-sig") as csv_file:
reader = csv.DictReader(csv_file)
# Make sure the file is formatted as expected
if set(expected_fields).intersection(set(reader.fieldnames)) != set(expected_fields):
print("CSV file column headers do not match expected values.")
print(f"Expected: {expected_fields}")
print(f"Found: {reader.fieldnames}")
exit(1)
for line in reader:
# Skip empty lines
if len("".join(v for v in line.values())) <= 0:
continue
print(f"Processing {line}")
output_filename = output_dir + "/" + "_".join((v for v in line.values() if v)) + ".stl"
# If the file exists, save time by not re-creating it
if os.path.exists(output_filename):
print(f" {output_filename} already exists")
else:
# Run openscad with the values from this line in the input file
subprocess.run(
[OPENSCAD,
'-o', output_filename,
'-D', f'BRAND="{line["Brand"]}"',
'-D', f'TYPE="{line["Type"]}"',
'-D', f'TYPE2="{line["Type2"]}"',
'-D', f'COLOR="{line["Color"]}"',
'-D', f'COLOR2="{line["Color2"]}"',
'-D', f'TEMP_BED="{line["Bed Temp"]}"',
'-D', f'TEMP_HOTEND="{line["Hotend Temp"]}"',
f'{MYDIR}/FilamentSamples.scad',
], check=True)
print()

if __name__ == "__main__":
gen_samples()
print()
parser = argparse.ArgumentParser()
parser.add_argument("--input-file", "-i", type=str, default="samples.csv", required=False, help="The path to the CSV file containing the filament info")
parser.add_argument("output_dir", default="stl", nargs="?", help="output directory to put the STL files into. Must be relative to the script directory")
args = parser.parse_args()

try:
gen_samples()
except Exception:
traceback.print_exc()
input("Press Enter to continue...")
finally:
print()
21 changes: 12 additions & 9 deletions samples.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
extrudr,Biofusion,Metallic Grey,225,60
extrudr,PETG,Black,230,80
JAYO,PLA+,Black,205,60
JAYO,PLA+ Silk,Red Copper,210,60
JAYO,PLA+ Silk,Light Gold,210,60
JAYO,PETG,Black,230,80
JAYO,PETG,Orange,230,80
ERYONE,PLA Matte,Navy Blue,215,60
OVERTURE,PETG,Rock White,235,80
Brand,Type,Type2,Color,Color2,Bed Temp,Hotend Temp
extrudr,Biofusion,,Metallic Grey,,225,60
extrudr,PETG,,Black,,230,80
JAYO,PLA+,,Black,,205,60
JAYO,PLA+ Silk,,Red Copper,,210,60
JAYO,PLA+ Silk,,Light Gold,,210,60
JAYO,PETG,,Black,,230,80
JAYO,PETG,,Orange,,230,80
ERYONE,PLA Matte,,Navy Blue,,215,60
OVERTURE,PETG,,Rock White,,235,80
polymaker,PolyLite,PETG,Electric Blue,#0076CF,80,240
Overture,PETG,,Red,,,
Loading