$fn = 64; // --- Parameters --- rail_length = 300; rail_width = 30; rail_thickness = 12; dovetail_inset = 5; num_holes = 5; hole_margin = 25; hole_diameter = 4.5; // Clearance for M4 screws head_diameter = 9.0; // M4 screw head diameter countersink_depth = 3.0; // --- Main Model --- difference() { // Rail Body (Dovetail Profile) hull() { // Base touching the wall translate([-rail_length/2, -rail_width/2, 0]) cube([rail_length, rail_width, 0.01]); // Top face of the rail translate([-rail_length/2, -rail_width/2 + dovetail_inset, rail_thickness - 0.01]) cube([rail_length, rail_width - 2*dovetail_inset, 0.01]); } // Mounting Holes for (i = [0 : num_holes - 1]) { x_pos = -rail_length/2 + hole_margin + i * ((rail_length - 2*hole_margin) / (num_holes - 1)); translate([x_pos, 0, 0]) { // Main screw shaft translate([0, 0, -1]) cylinder(h = rail_thickness + 2, d = hole_diameter); // Countersink for flathead screws translate([0, 0, rail_thickness - countersink_depth]) cylinder(h = countersink_depth + 0.02, d1 = hole_diameter, d2 = head_diameter); // Counterbore clearance (extends slightly above to ensure clean cut) translate([0, 0, rail_thickness]) cylinder(h = 1, d = head_diameter); } } }