This script generates a round belt intended to connect two pulleys. I needed a replacement belt for my son's rock tumbler so printed one with semi-flex filament. One week later and its still going strong, so I thought I'd publish the OpenSCAD script with customizer inputs for good measure.
The code to generate a torus is pretty simple using rotate_extrude(). Just make a circle, offset it along the x-axis and apply rotation. For a torus with major and minor radius of 48 and 1.5, the code would be
rotate_extrude() translate([48,0,0]) circle(r=1.5);
More of a challenge was determining the length of the belt based on the pulley sizes and distance between them. If you have the original, just measure it and compute the radius with
L / 2pi. If you don't have the original or if it's for a new design, there is some math involved. To make things a little easier I added this function to the script
function belt_length(R, r, d) = 2*d + PI*(R+r) + (R-r)*(R-r)/d;
Finally, to make printing easier, I added an option for an octagonal cross section. Because using circle() to generate regular polygons yields one that's circumscribed from the given radius, you might have to increase the belt thickness a little.