$fn=64; // --- Parameters --- length_units = 5; // Number of Gridfinity units long width_units = 1; // Number of Gridfinity units wide (1 for a standard rail) grid_size = 42; // Standard Gridfinity unit size base_height = 5.0; // Height of the rail base screw_hole_dia = 3.5; // Diameter of mounting screw shaft (M3 standard) screw_head_dia = 8.0; // Diameter of countersink head screw_head_height = 3.0;// Height of countersink // --- Calculated Variables --- rail_length = length_units * grid_size; rail_width = width_units * grid_size; module rounded_square(size, radius, h) { hull() { for (x = [-size[0]/2 + radius, size[0]/2 - radius]) { for (y = [-size[1]/2 + radius, size[1]/2 - radius]) { translate([x, y, 0]) cylinder(r=radius, h=h); } } } } module gridfinity_plug() { plug_w1 = 41.5; plug_r1 = 4.0; plug_w2 = 37.9; plug_r2 = 2.2; translate([0, 0, base_height - 0.01]) { // Lower straight section rounded_square([plug_w1, plug_w1], plug_r1, 0.81); // Chamfered middle section translate([0, 0, 0.8]) hull() { rounded_square([plug_w1, plug_w1], plug_r1, 0.01); translate([0, 0, 1.8]) rounded_square([plug_w2, plug_w2], plug_r2, 0.01); } // Upper straight section translate([0, 0, 2.6]) rounded_square([plug_w2, plug_w2], plug_r2, 1.8); } } module gridfinity_rail() { difference() { // Main Body union() { // Base strip translate([rail_length/2, rail_width/2, base_height/2]) cube([rail_length, rail_width, base_height], center=true); // Gridfinity Plugs for (x = [0 : length_units - 1]) { for (y = [0 : width_units - 1]) { translate([x * grid_size + grid_size/2, y * grid_size + grid_size/2, 0]) gridfinity_plug(); } } } // Mounting Holes for (x = [0 : length_units - 1]) { for (y = [0 : width_units - 1]) { translate([x * grid_size + grid_size/2, y * grid_size + grid_size/2, 0]) { // Screw shaft translate([0, 0, -1]) cylinder(d=screw_hole_dia, h=base_height + 10); // Countersink translate([0, 0, base_height - screw_head_height]) cylinder(d1=screw_hole_dia, d2=screw_head_dia, h=screw_head_height + 0.02); // Clearance for screw head through the plug translate([0, 0, base_height]) cylinder(d=screw_head_dia, h=10); } } } } } gridfinity_rail();