Created
July 17, 2022 19:31
-
-
Save codebykyle/c7e7929d33b50f871b145d89480dd81b to your computer and use it in GitHub Desktop.
3D printed wire and tube holder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*************************** | |
******* USER PARAMS ******* | |
**************************/ | |
/* [Resolution Options] */ | |
// Resolution of the mode. | |
// Lower values render faster. | |
// Higher values are smoother. | |
$fn = 100; | |
/* [Global Options] */ | |
// How tall the part should be | |
HEIGHT = 20; | |
// How thick the part should be | |
THICKNESS = 10; | |
// How much slop should we account for in our fitting of parts | |
SLOP = .3; | |
/* [Main Body] */ | |
// The center section where this will attach | |
CENTER_WIDTH = 50; | |
/* [Offset Connector Options] */ | |
// Controls the steepness of the angle from the outer wings to the center section | |
OFFSET_WIDTH = 20; | |
// Controls how deep to offset the wings from the face | |
OFFSET_DEPTH = 20; | |
// How rounded should the offset corners be | |
OFFSET_FILLET = 5; | |
/* [Wing Options] */ | |
// The amount of space to extend beyond the offset and the center | |
WING_LENGTH = 30; | |
// At the very end of the wings, we can set a fillet diameter | |
WING_FILLET = 5; | |
/* [Faceplate Options] */ | |
// How deep should the faceplate hole be | |
// note: this can be used to sink screws behind the faceplate, or as registration | |
FACE_PLATE_DEPTH = 5; | |
// How wide should the faceplate be | |
FACE_PLATE_WIDTH = 50; | |
// How tall should the faceplate be | |
FACE_PLATE_HEIGHT = 20; | |
// How thick should the faceplate be | |
FACE_PLATE_THICKNESS = 5; | |
// Roundness of the corners of the faceplate | |
FACE_PLATE_FILLET = 5; | |
// How far from the edge should the inset be which is used to attach to the center plate | |
FACE_PLATE_REGISTRATION_INSET = 3; | |
// How thick should the registration band be | |
FACE_PLATE_REGISTRATION_THICKNESS = 3; | |
// Should the face plate have screw holes | |
FACE_PLATE_SCREW_HOLES = true; | |
/* [Screw Options] */ | |
// How big to make the holes for screws | |
SCREW_DIAMETER = 5; | |
// Distance between the screws | |
SCREW_DISTANCE = 20; | |
/*************************** | |
**** CALCULATED PARAMS **** | |
**************************/ | |
// Calculated total width of the part | |
CALC_OFFSET_START = CENTER_WIDTH / 2; | |
// Calculated total width of the object | |
CALC_TOTAL_WIDTH = CENTER_WIDTH + 2 * (OFFSET_WIDTH + WING_LENGTH); | |
// How much to shift the wing over from the center point | |
CALC_WING_OFFSET = CALC_OFFSET_START + OFFSET_WIDTH; | |
// The part is mirrored once it has been finished. We only need to model half the part. Calculate half dimensions | |
CALC_CENTER_BODY_DIMENSIONS = [ | |
HEIGHT, | |
CENTER_WIDTH / 2, | |
THICKNESS | |
]; | |
// Half of the wing fillet which is stored as a diameter | |
CALC_WING_FILLET_RADIUS = WING_FILLET / 2; | |
// The length of the wing minus the piece for the fillet | |
CALC_WING_LENGTH_MINUS_FILLET = WING_LENGTH - CALC_WING_FILLET_RADIUS; | |
// The box dimensions of the wing | |
CALC_WING_DIMENSIONS = [ | |
HEIGHT, | |
CALC_WING_LENGTH_MINUS_FILLET | |
]; | |
// The length of the connector that connects the center body to the wing | |
CALC_CONNECTOR_LENGTH = sqrt( | |
OFFSET_DEPTH * OFFSET_DEPTH + | |
OFFSET_WIDTH * OFFSET_WIDTH | |
); | |
// The angle from the origin to the wings | |
CALC_ANGLE_FROM_BASE_TO_WING = atan2(OFFSET_DEPTH, OFFSET_WIDTH); | |
module triangle(o_len, a_len, center=false) | |
{ | |
centroid = center ? [-a_len/3, -o_len/3, 0] : [0, 0, 0]; | |
translate(centroid) | |
polygon(points=[ | |
[0,0], | |
[a_len,0], | |
[0,o_len] | |
], paths=[[0,1,2]]); | |
} | |
// Creates a "skewed" box | |
function rhomboid(x=1, y=1, angle=90) | |
= [[0,0],[x,0], | |
[x+x*cos(angle)/sin(angle),y], | |
[x*cos(angle)/sin(angle),y]]; | |
// Creates a filleted edge for use at the end of a square | |
module create_fillet_end(length, d) { | |
fillet_radius = d / 2; | |
length_minus_fillet = length - fillet_radius; | |
height_minus_fillet = length - fillet_radius; | |
corner_offset_1 = [fillet_radius, 0, 0]; | |
corner_offset_2 = [length_minus_fillet, 0, 0]; | |
tan_square_dimensions = [length - d, d]; | |
tan_square_offset = [fillet_radius, -fillet_radius, 0]; | |
union() { | |
translate(corner_offset_1) | |
circle(r=fillet_radius); | |
translate(corner_offset_2) | |
circle(r=fillet_radius); | |
translate(tan_square_offset) | |
square(tan_square_dimensions, center=false); | |
} | |
} | |
// Creates a rounded square | |
module create_rounded_square(h, w, d, center=false) { | |
h2 = (h - d) / 2; | |
w2 = (w - d) / 2; | |
centroid = center ? [0, 0, 0] : [h / 2, 0, 0]; | |
translate(centroid) | |
hull() { | |
translate([h2, w2]) | |
circle(d=d); | |
translate([-h2, w2]) | |
circle(d=d); | |
translate([h2, -w2]) | |
circle(d=d); | |
translate([-h2, -w2]) | |
circle(d=d); | |
} | |
} | |
module generate_base_shape() { | |
// Create the base shape | |
union() { | |
// Make half of the center body | |
cube(size=CALC_CENTER_BODY_DIMENSIONS, center=false); | |
// Make a connector which goes from the body to the wing | |
translate([0, CALC_OFFSET_START, 0]) | |
union() { | |
hull() { | |
cube(size=[HEIGHT, THICKNESS, THICKNESS], center=false); | |
translate([0, OFFSET_WIDTH-THICKNESS, OFFSET_DEPTH]) | |
cube(size=[HEIGHT, THICKNESS, THICKNESS], center=false); | |
} | |
} | |
// Make a single wing which is offset | |
translate([0, CALC_WING_OFFSET, OFFSET_DEPTH]) | |
linear_extrude(height=THICKNESS, center=false) | |
union() { | |
// Body that will attach to the tangent of the fillet end | |
square(CALC_WING_DIMENSIONS, center=false); | |
// Creates a square with circle endcaps | |
translate([0, CALC_WING_LENGTH_MINUS_FILLET, 0]) | |
create_fillet_end(HEIGHT, WING_FILLET); | |
} | |
} | |
} | |
module generate_part() { | |
difference() { | |
union() { | |
generate_base_shape(); | |
mirror([0, 1, 0]) { | |
generate_base_shape(); | |
} | |
} | |
// Create a pocket for the faceplate to snap into | |
translate([FACE_PLATE_HEIGHT / 2, 0, THICKNESS - FACE_PLATE_DEPTH - SLOP + 0.01]) | |
linear_extrude(FACE_PLATE_DEPTH + SLOP + 0.02) | |
create_rounded_square( | |
FACE_PLATE_HEIGHT - FACE_PLATE_REGISTRATION_INSET - SLOP, | |
FACE_PLATE_WIDTH - FACE_PLATE_REGISTRATION_INSET - SLOP, | |
FACE_PLATE_FILLET, | |
center=true | |
); | |
// Create the screw holes | |
union() { | |
translate([HEIGHT / 2, SCREW_DISTANCE, -0.5]) | |
cylinder(d=SCREW_DIAMETER + SLOP, h=THICKNESS + 2, center=false); | |
translate([HEIGHT / 2, -SCREW_DISTANCE, -0.5]) | |
cylinder(d=SCREW_DIAMETER + SLOP, h=THICKNESS + 2, center=false); | |
} | |
} | |
//Make the face cap | |
difference() { | |
// Create the faceplate | |
#translate([FACE_PLATE_HEIGHT / 2, 0, THICKNESS]) | |
union() { | |
// Create the inset registration | |
translate([0,0,-FACE_PLATE_DEPTH]) | |
difference() { | |
linear_extrude(FACE_PLATE_DEPTH) | |
create_rounded_square( | |
FACE_PLATE_HEIGHT - FACE_PLATE_REGISTRATION_INSET - SLOP, | |
FACE_PLATE_WIDTH - FACE_PLATE_REGISTRATION_INSET - SLOP, | |
FACE_PLATE_FILLET, | |
center=true | |
); | |
translate([0,0, -.01]) | |
linear_extrude(FACE_PLATE_DEPTH + 0.02) | |
create_rounded_square( | |
FACE_PLATE_HEIGHT - FACE_PLATE_REGISTRATION_INSET - FACE_PLATE_REGISTRATION_THICKNESS - SLOP, | |
FACE_PLATE_WIDTH - FACE_PLATE_REGISTRATION_INSET - FACE_PLATE_REGISTRATION_THICKNESS - SLOP, | |
FACE_PLATE_FILLET, | |
center=true | |
); | |
} | |
// Create the main body of the faceplate | |
linear_extrude(FACE_PLATE_THICKNESS) | |
create_rounded_square( | |
FACE_PLATE_HEIGHT, | |
FACE_PLATE_WIDTH, | |
FACE_PLATE_FILLET, | |
center=true | |
); | |
} | |
if (FACE_PLATE_SCREW_HOLES) { | |
// Create the screw holes | |
union() { | |
translate([HEIGHT / 2, SCREW_DISTANCE, -0.5]) | |
cylinder(d=SCREW_DIAMETER + SLOP, h=FACE_PLATE_HEIGHT + 2, center=false); | |
translate([HEIGHT / 2, -SCREW_DISTANCE, -0.5]) | |
cylinder(d=SCREW_DIAMETER + SLOP, h=FACE_PLATE_HEIGHT + 2, center=false); | |
} | |
} | |
} | |
} | |
generate_part(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment