I’m relatively new to python, and have started learning for the above reason.
I want to be able to model guitar necks (and then cut on a CNC router) relatively quickly, but most of all accurately (which is where the scripting comes in)
The fret slot distances use a constant (17.81…) divided by the string length which is repeated 22+ times with an ever shortening string length. Online I have found a python version of a trusted calculator and was wondering if anyone had tips/ideas on connecting the mathematics in said calculator to something like rs.addpoint (or addline) to create an array of points/lines in the correct spacing.
Below is the fret calculator script.
# From Stewmac
# To calculate the scale length for stringed instruments
# Notes on fret layout
# The most accurate way to lay out your scale is making all measurements
# from the nut (using the "fret to fret" distance only to confirm your layout).
# Laying out frets only by measuring fret to fret will compound error.
# For example, if you're laying out frets by marking with a scribe and your
# accuracy is plus or minus 2 millimeters, you could be off by as much as
# 24 millimeters at the 12th fret.
# Measurements are given from the end of the fingerboard (face of the nut)
# to the center of a fret slot.
# WRITTEN FOR PYTHON 3.3.2
#--------------------------------------------------------------------
Im = ''
const = 17.817 # Do not change this
def fretCal(ScaleLength, nofret):
'''(number, number)-> float
Calculates the fret positions for any stringed instrument
Given 'Scale length', 'number of frets' in inches or mm
>>> fretCal(19, 18)
Fret 1 from nut 1.066 inches
Fret 2 from nut 2.073 inches
............................
>>> fretCal(635, 22)
Fret 1 from nut 35.64 mm
Fret 2 from nut 69.28 mm
'''
if ScaleLength < 99:
scale = ScaleLength
Im = 'inches'
if ScaleLength > 100:
scale = ScaleLength
Im = 'mm'
for i in range(1, nofret +1):
ScaleLength = ScaleLength - (ScaleLength / const)
print('Fret', i, 'from nut',round(scale - ScaleLength, 3),Im)
#--------------------------------------------------------------------
Hope someone can help!
Oliver