module h_bar(thickness, n_holes, hole_rad, hole_sep, alpha){ // n_holes = number of holes // hole_rad = radius of holes // hole _sep = distance between holes // alpha and beta are to adjust the bar length and width // bar length depends on the number of holes wanted and the distance between them bar_length = n_holes*(2*hole_rad) + (n_holes - 1)*hole_sep + 2*hole_sep*alpha; // bar width only depends on the distance between holes bar_width = 2*hole_rad + 2*hole_sep*alpha; module bar(){ //if n_holes = 0 nothing is done if (n_holes > 0) //creates the bar without holes hull() { translate([(bar_length/2)-(bar_width/2),0,0]) cylinder(h=thickness, r=bar_width/2); translate([-(bar_length/2)+(bar_width/2),0,0]) cylinder(h=thickness, r=bar_width/2); } } //distance center-center of two holes center_dist = 2*hole_rad + hole_sep; //distance of the furthest hole max_center = (n_holes-1)*hole_rad + ((n_holes-1)/2)*hole_sep; //adds holes starting from the furthest hole on "-x" axis up to furthest hole in "+x" axis difference() { bar(); for (dx=[-max_center:center_dist:max_center]) { translate([dx, 0, 0]) cylinder(h=3*thickness, r=hole_rad, center=true); } } } // test //h_bar(5, 3, 3, 2, 0.95);