#!/usr/bin/env python3 # type: ignore # ************************************************************************* # Copyright (C) 2025, Paul Lutus * # * # This program is free software; you can redistribute it and/or modify * # it under the terms of the GNU General Public License as published by * # the Free Software Foundation; either version 2 of the License, or * # (at your option) any later version. * # * # This program is distributed in the hope that it will be useful, * # but WITHOUT ANY WARRANTY; without even the implied warranty of * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * # GNU General Public License for more details. * # * # You should have received a copy of the GNU General Public License * # along with this program; if not, write to the * # Free Software Foundation, Inc., * # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * # ************************************************************************* import cadquery as cq import copy import math, sys # a classic interpolation algorithm def ntrp(x, xa, xb, ya, yb): return (x - xa) * (yb - ya) / (xb - xa) + ya def show_results(item): try: show_object(item) except: None # print(" The show_object() function only works in CQ-Editor.") def generate_tensioner(testing=False): # external arc disc_a = cq.Workplane("YZ").circle(5.0).extrude(1.75).translate((-0.875, 12, 15)) # shoulder disc_b = cq.Workplane("YZ").circle(2.75).extrude(3).translate((-1.5, 12, 15)) # pulley axle port perf_a = cq.Workplane("YZ").circle(1.35).extrude(24).translate((-12, 12, 15)) # tensioner adjustment brass insert port perf_b = cq.Workplane("XZ").circle(2).extrude(24).translate((0, 20, 4)) # pulley for testing pulley = cq.Workplane("YZ").circle(8.5).extrude(9).translate((-4.5, 12, 15)) insert = cq.Workplane("XZ").circle(2).extrude(8).translate((0, 8.5, 4)) # see solvespace source file for dimension numbers edge_points_A = ( (0.5, 0.0), (0.0, 0.5), (0.0, 8.0), (3.050, 11.814), (4.205, 9.570), (6.169, 7.5), (7.653, 6.553), (17.0, 3.0), (17.0, 1.0), (16.0, 0.0), (0.5, 0.0), ) edge_points_B = ( (0.5, 0.0), (0.0, 0.5), (0.0, 8.0), (8.1, 18.12), # arc fills in here (17.0, 15.0), (17.0, 1.0), (16.0, 0.0), (0.5, 0, 0), ) edge_points_C = ( (0.0, 6.75), (0.0, 8.0), (8.1, 18.123), # arc fills in here (17.0, 15.0), (17.0, 6.75), (0.0, 6.75), ) body_a = ( cq.Workplane("YZ") .polyline(edge_points_A) .close() .extrude(11) .edges("X") .fillet(0.8) .translate((-5.5, 0, 0)) ) body_b = ( cq.Workplane("YZ") .polyline(edge_points_B) .close() .extrude(1.75) .edges("X") .fillet(0.8) .translate((-0.875, 0, 0)) ) body_c = ( cq.Workplane("YZ") .polyline(edge_points_C) .close() .extrude(1.75) .edges("X") .fillet(0.8) .translate((-0.875, 0, 0)) ) body_b1 = (body_b + disc_a + disc_b).translate((6.25, 0, 0)) body_b2 = (body_b + disc_a + disc_b).translate((-6.25, 0, 0)) body_c1 = (body_c + disc_a + disc_b).translate((8, 0, 0)) body_c2 = (body_c + disc_a + disc_b).translate((-8, 0, 0)) body = body_a + body_b1 + body_b2 + body_c1 + body_c2 - (perf_a + perf_b) if testing: body += pulley body += insert show_results(body) return body def dispatch(testing): ts = ("", "_testing")[testing] body = generate_tensioner(testing) fn = f"belt_tensioner_cadquery{ts}.stl" body.export(fn) print(f"wrote {fn}.") def main(): dispatch(True) dispatch(False) if __name__ == "__main__": main()