-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgridfinity_box_label.scad
More file actions
577 lines (440 loc) · 18.9 KB
/
gridfinity_box_label.scad
File metadata and controls
577 lines (440 loc) · 18.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
//------------------------------------------------------
/* [General customization] */
//Label size
Y_units = 5; // [4,5,7,8]
//Show Divider line
Show_Divider = true;
// Choose logo type: emoji, character, or hardware icons
LOGO_TYPE = "char"; // ["emoji", "char", "hardware", "none"]
/* [Emoji settings] */
LOGO_EMOJI = "🌐"; //[😂,💻, ❤️,😍,🤣,😊,🥺,🙏,💕,😭,😘,👍,😅,👏,🥰,💀,✌️,😬,👀,😏,😒,😳,😜,😎,😇,🐵,🐶,🐺,🦊,🐱,🦁,🐯,🐴,🦄,🐮,🐷,🐭,🐹,🐰,🦓,🐻,🐼,🦘,🦡,🐨,🐔,🐦,🐤,🦉,🌴,🌵,🌷,🌻,🌼,🍂,🍁,🌾,🌱,🍄,🌲,🌳,🌿,☘️,🍀,🌹,🌺,🌸,🌞,🌝,🌛,🌜,🌚,🌕,🍏,🍎,🍐,🍊,🍋,🍌,🍉,🍇,🍓,🍈,🍒,🍑,🍍,🥭,🥥,🥝,🍅,🥑,🍆,🥒,🥬,🌶️,🌽,🥕,🍰,🎂,🧁,🍦,🍧,🍨,🍩,🍪,🍫,🍬,🍭,🍮,🍯,🍼,🥛,🍵,🍶,🍾,🍷,🍸,🍹,🍺,🍻,🥂,⚽,🏀,🏈,⚾,🎾,🏐,🏉,🎱,🏓,🏸,🥅,🏒,🏑,🏏,🥊,🥋,🎿,⛷,🏂,🏋️♂️,🤸♀️,⛹️♂️,🤾♀️,🏌️♂️,🚗,🚕,🚙,🚌,🚎,🏎,🚓,🚑,🚒,🚐,🛴,🚲,🛵,🏍,🚨,🚔,🚍,🚘,🚖,🚡,🚠,🚟,🚃,🚞,🏡,🏘,🏠,🏚,🏢,🏬,🏣,🏤,🏥,🏦,🏨,🏪,🏫,🏩,🏛,🏺,🕌,🕍,🕋,⛪,🛤,🛣,🗽,🏰,🎁,🎀,🎊,🎉,🎈,🎂,🎌,🎏,🎄,🎅,🤶,🦌,🧧,🎎,🏮,🎐,🧨,🎇,🎆,🎋,🎍,🎠,🎡,🎢,👓,🕶,🥽,🥼,🌂,🧵,🧶,👔,👕,👖,🧣,🧤,🧥,🧦,👗,👘,👙,👚,👛,👜,👝,🎒,👞,👟,🧿,🔮,💡,🔦,🏮,📽,🎬,📸,📹,🎥,🎞,📺,📻,🎙,🎚,🎛,🧭,🧱,🔨,🛠,🗡,⚔️,🔪,🏹,🎵,🎶,📯,🎤,🎧,🎷,🎸,🎹,🎻,🎺,🥁,🪘,📣,📢,👾,🎮,🕹,🎰,🖨,🖱,🖲,💾,💿,📀,🚀,🛸,🛰,🛳,🚢,🚤,🛶,⛴,🛥,🚜,🚛,🚚,🚒,🚑,🚓,🚍,🚔,🚘,🚖,🚡,🚠,🚟,🚃,🚞,💯,✅,❌,⭕,🔝,🔜,🔚,🔙,🔛,🔱,🔆,🔅,📛,🔰,💤,🚷,🚯,🚳,🚱,🔞,📵,🚭,❗,❓,🕊️,🦜,🦢,🦉,🦚,🦜,🦩,🦚,🦤,🦉,🐉,🐲,🦕,🦖,🐍,🦎,🦗,🐜,🦟,🦠,🕷,🕸,🐚,🦞,🌌,🪐,⭐,🌟,🌠,🌜,🌛,🌚,🌕,🌖,🌗,🌘,🌑,🌒,🌓,🌔,🌙,🌎,🌍,🌏,🌐,🗺,🧭,🏞,🍟,🍔,🌭,🍕,🍖,🍗,🥩,🥓,🥚,🥯,🍞,🥖,🥨,🧀,🥞,🧇,🥓,🍳,🥚,🍳,🍜,🍲,🍛,🍣,🧸,🪀,🪁,🪂,🪃,🏹,🪆,🎭,🎨,🧵,🧶,🎯,🎮,🎲,🎳,🎴,🎠,🎡,🎢,🎪,🤹,🪄,🎭,🎨,🤖,👽,👻,💩,👺,👹,👾,🎃,👼,🤡,🧙,🧛,🧟,🧞,🧜,🧚,🧝,🧙♂️,🧙♀️,🧚♂️,🧚♀️,🧛♂️,🧛♀️,🧜♂️,🧜♀️]
/* [Character settings ] */
LOGO_CHAR = "M3";
LOGO_SIZE = 12; //[8:16]
LOGO_ROTATION = 0; //[0:90]
/* [Hardware settings ] */
Hardware_type = "Socket head bolt"; // [Socket head bolt, Hex head bolt, Dome head bolt, Countersunk socket head bolt, Standard washer, Spring washer, Standard nut]
/* [Text customization] */
Line_1_text = "Bolts";
Line_2_text = "Nuts";
Line_3_text = "Washers";
Line_4_text = "Inserts";
Filter_Empty_Lines = true;
// Introduce a line spacing factor for additional vertical spacing
line_spacing_factor = 1.5; // Increase this to add more space between lines
//Flush text requires an AMS
text_type = "Raised Text"; // [Raised Text, Flush Text]
// Raised Text Height
text_height = .2;
// ;
//Font type
text_font = "Noto Sans SC:Noto Sans China"; // [HarmonyOS Sans, Inter, Inter Tight, Lora, Merriweather Sans, Montserrat, Noto Sans, Noto Sans SC:Noto Sans China, Noto Sans KR, Noto Emoji, Nunito, Nunito Sans, Open Sans, Open Sans Condensed, Oswald, Playfair Display, Plus Jakarta Sans, Raleway, Roboto, Roboto Condensed, Roboto Flex, Roboto Mono, Roboto Serif, Roboto Slab, Rubik, Source Sans 3, Ubuntu Sans, Ubuntu Sans Mono, Work Sans]
//Font Style
Font_Style = "Bold"; // [Regular,Black,Bold,ExtraBol,ExtraLight,Light,Medium,SemiBold,Thin,Italic,Black Italic,Bold Italic,ExtraBold Italic,ExtraLight Italic,Light Italic,Medium Italic,SemiBold Italic,Thin Italic]
//Font size
text_size = 4.2;
// Set a margin factor (adjustable)
margin_factor = 0.15; // 15% margin on top and bottom
/* [Additional settings] */
width=24.5;
height=0.85;
radius= 3.5;
champfer=0.2;
$fs = 0.1;
$fa = 5;
/* [Hidden] */
Font = str(text_font, ":style=", Font_Style);
length = getDimensions(Y_units); // Set length based on Y_units value
z_max = height + ((text_type == "Raised Text") ? text_height : 0.02);
label(
length = length,
width = width,
height = height,
radius = radius,
champfer = champfer
);
// Corrected function for setting length based on Y_units
function getDimensions(Y_units) =
(Y_units == 4) ? 25.5 :
(Y_units == 5) ? 67.5 :
(Y_units == 7) ? 82 :
(Y_units == 8) ? 100 : 0; // Default value if no match
module label(length, width, height, radius, champfer)
{
color("black") {
difference() {
__shapeWithChampfer(
length,
width,
height,
radius,
champfer
);
}
}
color("white") {
render_logo();
if (Y_units > 4){
//translate([((length / 2) + width / 2), width * (2 / 5), 0])
render_text();
}
}
}
module render_text() {
// Array of text lines
non_empty_lines = Filter_Empty_Lines
? [for (line = [Line_1_text, Line_2_text, Line_3_text, Line_4_text]) if (line != "") line]
: [Line_1_text, Line_2_text, Line_3_text, Line_4_text];
// Calculate number of lines and spacing
num_lines = len(non_empty_lines);
line_spacing = text_size * line_spacing_factor;
if (num_lines > 0) {
// Calculate the total height of the text block
total_text_height = (num_lines - 1) * line_spacing + text_size;
// Determine vertical and horizontal offsets
x_offset = (LOGO_TYPE != "none") ? (length / 2 + width / 2) : (length / 2);
y_offset = width / 2; // Center the block vertically on the object
// Adjust for proper vertical centering of the text block
y_start = y_offset + total_text_height / 2 - text_size / 2;
// Render each line
linear_extrude(z_max) {
for (i = [0 : num_lines - 1]) {
// Position each line from top to bottom
y_position = y_start - (i * line_spacing);
translate([
x_offset, // Center horizontally
y_position, // Correct vertical centering
0 // Z-position
])
text(
non_empty_lines[i], // Correct line order
size = text_size,
font = Font,
halign = "center", // Center text horizontally
valign = "center" // Center text vertically
);
}
}
} else {
echo("No lines to render!");
}
}
module render_logo( logo_name) {
if (LOGO_TYPE != "none") {
if (LOGO_TYPE == "emoji"){
render_emoji(LOGO_EMOJI);
}
if (LOGO_TYPE == "char"){
render_char(LOGO_CHAR);
}
if (LOGO_TYPE == "hardware"){
render_hardware(Hardware_type);
}
if (Show_Divider && Y_units > 4){
// Render the divider line next to the logo
translate([width, width / 2 - (width * 0.8) / 2, 0])
cube([1, width * 0.8, z_max]);
}
}
}
module render_emoji(LOGO) {
linear_extrude(z_max)
color("red")
translate([(width/2), width / 2, 0])
rotate([0,0,LOGO_ROTATION])
rotate([0,0,0])
text(LOGO, font="Noto Emoji:style=Bold", size=LOGO_SIZE, halign="center", valign="center");
}
module render_char(LOGO) {
linear_extrude(z_max)
translate([(width/2), width / 2, 0])
rotate([0,0,LOGO_ROTATION])
rotate([0,0,-0])
text(LOGO, size=LOGO_SIZE, halign="center", valign="center");
}
//module render_hardware(Hardware_type) {
// linear_extrude(z_max)
//
// color("red")
// translate([(width/2), width / 2, 0])
// rotate([0,0,LOGO_ROTATION])
// rotate([0,0,0])
// text(LOGO, font="Noto Emoji:style=Bold", size=LOGO_SIZE, halign="center", valign="center");
//}
// Function to select the appropriate bolt head module
module render_hardware(Part_version, bolt_length = 8, width = width, height = height) {
translate([width/2, 0, 0])
if (Part_version == "Socket head bolt") {
Socket_head(bolt_length, width, height);
} else if (Part_version == "Hex head bolt") {
Hex_head(bolt_length, width, height);
} else if (Part_version == "Countersunk socket head bolt") {
Countersunk_socket_head(bolt_length, width, height);
} else if (Part_version == "Dome head bolt") {
Dome_head(bolt_length, width, height);
} else if (Part_version == "Standard washer") {
standard_washer(width, height);
} else if (Part_version == "Spring washer") {
spring_washer(width, height);
} else if (Part_version == "Standard nut") {
standard_Nut(width, height);
}
}
// Hardware icons generators --------------------------
module standard_Nut(width, height, vertical_offset = width/2) {
// Center the icon
translate([-4, vertical_offset, height]) {
// Top view of the bolt head
difference() {
cylinder(h=text_height, d=11, $fn=6);
cylinder(h=text_height, d=6);
}
translate([7, -5, 0])
cube([5.6, 10, text_height]);
}
}
module standard_washer(width, height, vertical_offset = width/2) {
// Center the icon
translate([-2.5, vertical_offset, height]) {
// Top view of the bolt head
difference() {
cylinder(h=text_height, d=10);
cylinder(h=text_height, d=6);
}
translate([7, -5, 0])
cube([2, 10, text_height]);
}
}
module spring_washer(width, height, vertical_offset = width/2) {
// Center the icon
translate([-1.5, vertical_offset, height]) {
// Top view of the bolt head
difference() {
cylinder(h=text_height, d=10);
cylinder(h=text_height, d=6);
cube([5, 1.6, text_height]);
}
translate([7, -5, 0])
cube([2, 10, text_height]);
}
}
// Bolt icons modules ------------------------------------------------------
module Socket_head(bolt_length, width, height, vertical_offset = width/2) {
// Set the display length to 20 if bolt_length exceeds 20
display_length = (bolt_length > 20) ? 20 : bolt_length;
// Center the entire icon horizontally based on display_length
translate([-display_length / 2 - 2, vertical_offset, height]) {
// Top view of the bolt head
difference() {
cylinder(h=text_height, d=5);
cylinder(h=text_height, r=1.6, $fn=6);
}
// Side view of the bolt head
translate([3, -2.5, 0])
cube([4, 5, text_height]);
// Side view of the bolt stem, with a gap if bolt_length > 20
if (bolt_length > 20) {
// Cap the visible length at 20 units and add a gap in the middle
translate([7, -1.25, 0])
cube([8.5, 2.5, text_height]); // First half (10 units)
translate([7 + 12, -1.25, 0])
cube([8.5, 2.5, text_height]); // Second half (10 units)
} else {
// Regular full-length stem if bolt_length <= 20
translate([7, -1.25, 0])
cube([bolt_length, 2.5, text_height]);
}
}
}
module Hex_head(bolt_length, width, height, vertical_offset = width/2) {
// Set the display length to 20 if bolt_length exceeds 20
display_length = (bolt_length > 20) ? 20 : bolt_length;
// Center the entire icon horizontally based on display_length
translate([-display_length / 2 - 2, vertical_offset, height]) {
// Top view of the bolt head
cylinder(h=text_height, d=5, $fn=6);
// Side view of the bolt head
translate([3, -2.5, 0])
cube([3, 5, text_height]);
// Side view of the bolt stem, with a gap if bolt_length > 20
if (bolt_length > 20) {
// Cap the visible length at 20 units and add a gap in the middle
translate([6, -1.25, 0])
cube([8.5, 2.5, text_height]); // First half (10 units)
translate([6 + 12, -1.25, 0])
cube([8.5, 2.5, text_height]); // Second half (10 units)
} else {
// Regular full-length stem if bolt_length <= 20
translate([6, -1.25, 0])
cube([bolt_length, 2.5, text_height]);
}
}
}
module Countersunk_socket_head(bolt_length, width, height, vertical_offset = width/2) {
// Set the display length to 20 if bolt_length exceeds 20
display_length = (bolt_length > 20) ? 20 : bolt_length;
// Center the entire icon horizontally based on display_length
translate([-display_length / 2 - 2, vertical_offset, height]) {
// Top view of the bolt head
difference() {
cylinder(h=text_height, d=5);
cylinder(h=text_height, r=1.6, $fn=6);
}
// Side view of the bolt head
translate([5, 0, 0])
//triangle
cylinder(r=3, h=text_height, $fn=3);
// Side view of the bolt stem, with a gap if bolt_length > 20
if (bolt_length > 20) {
// Cap the visible length at 20 units and add a gap in the middle
translate([5, -1.25, 0])
cube([8.5, 2.5, text_height]); // First half (10 units)
translate([5 + 12, -1.25, 0])
cube([8.5, 2.5, text_height]); // Second half (10 units)
} else {
// Regular full-length stem if bolt_length <= 20
translate([5, -1.25, 0])
cube([bolt_length, 2.5, text_height]);
}
}
}
module Dome_head(bolt_length, width, height, vertical_offset = width/2) {
// Set the display length to 20 if bolt_length exceeds 20
display_length = (bolt_length > 20) ? 20 : bolt_length;
// Center the entire icon horizontally based on display_length
translate([-display_length / 2 - 2, vertical_offset, height]) {
// Top view of the bolt head
difference() {
cylinder(h=text_height, d=5);
cylinder(h=text_height, r=1.6, $fn=6);
}
// Side view of the bolt head
translate([6, 0, 0])
difference() {
cylinder(h=text_height, d=5);
translate([0, -2.5, 0])
cube([4, 5, text_height]);
}
// Side view of the bolt stem, with a gap if bolt_length > 20
if (bolt_length > 20) {
// Cap the visible length at 20 units and add a gap in the middle
translate([6, -1.25, 0])
cube([8.5, 2.5, text_height]); // First half (10 units)
translate([6 + 12, -1.25, 0])
cube([8.5, 2.5, text_height]); // Second half (10 units)
} else {
// Regular full-length stem if bolt_length <= 20
translate([6, -1.25, 0])
cube([bolt_length, 2.5, text_height]);
}
}
}
// Shape designer functions --------------------------
module __shapeWithChampfer(
length=160,
width=120,
height=40,
radius=10,
champfer=4
)
{
// Apply chamfer at the bottom
translate([0, 0, 0])
__champfer(length, width, champfer, radius, flip=false);
// Apply the main shape, reduced in height to account for both chamfers
translate([0, 0, champfer])
__shape(length, width, height - 2 * champfer, radius);
// Apply chamfer at the top
translate([0, 0, height - champfer])
__champfer(length, width, champfer, radius, flip=true);
}
module __shapeWithFillet(
length=160,
width=120,
height=40,
radius=10,
fillet=4,
flip=false
)
{
fillet_size = min(fillet, radius / 2);
start1 = (flip == true) ? height - fillet_size : 0;
start2 = (flip == true) ? 0 : fillet_size;
hull() {
translate([0, 0, start1])
__fillet(length, width, fillet_size, radius, flip);
translate([0, 0, start2])
__shape(length, width, height - champfer, radius);
}
}
module __fillet (
length=160,
width=120,
size=4,
radius=10,
flip=false
) {
start_fillet = (flip == true) ? 0 : size;
start_cutout = (flip == true) ? - size - 1: size;
difference() {
translate([0,0,start_fillet])
hull () {
rotate(180)
translate ([- radius, - radius, 0])
rotate_extrude(angle = 90)
translate([radius - size, 0, 0])
circle(r = size, $fn = 100);
rotate(90)
translate ([width - radius, - radius, 0])
rotate_extrude(angle = 90)
translate([radius - size, 0, 0])
circle(r = size, $fn = 100);
rotate(0)
translate ([length - radius, width - radius, 0])
rotate_extrude(angle = 90)
translate([radius - size, 0, 0])
circle(r = size, $fn = 100);
rotate(270)
translate ([- radius, length - radius, 0])
rotate_extrude(angle = 90)
translate([radius - size, 0, 0])
circle(r = size, $fn = 100);
}
translate([0,0,start_cutout])
hull() {
translate ([radius, radius, 0]) cylinder (h = size + 1, r=radius);
translate ([radius, width-radius, 0]) cylinder (h = size + 1, r=radius);
translate ([length-radius,width-radius, 0]) cylinder (h = size + 1, r=radius);
translate ([length-radius, radius, 0]) cylinder (h = size + 1, r=radius);
}
}
}
module __champfer (
length=160,
width=120,
size=4,
radius=10,
flip=false
) {
r1 = (flip == true) ? radius : radius - size;
r2 = (flip == true) ? radius - size : radius;
hull() {
translate ([radius, radius, 0]) cylinder (h = size, r1=r1, r2=r2);
translate ([radius, width-radius, 0]) cylinder (h = size, r1=r1, r2=r2);
translate ([length-radius,width-radius, 0]) cylinder (h = size, r1=r1, r2=r2);
translate ([length-radius, radius, 0]) cylinder (h = size, r1=r1, r2=r2);
}
}
module __shape(
length=160,
width=120,
height=40,
radius=10,
){
hull() {
translate ([radius, radius, 0]) cylinder (h = height, r=radius);
translate ([radius, width-radius, 0]) cylinder (h = height, r=radius);
translate ([length-radius,width-radius, 0]) cylinder (h = height, r=radius);
translate ([length-radius, radius, 0]) cylinder (h = height, r=radius);
}
}