Thank you both! Regarding cq_warehouse's clearanceHoles, I wondered if it would work for something I commonly do. Since I use resin printing, FDM, and CNC stuff, a clearance hole might have many different sizes. It might also expand to the size it'd need to be to hold a heat-inserted nut. So, in my personal library (of SolidPython code), I've always stored many values on each thing, like this:
class Bolt:
def draw(self, ):
class M3Bolt(Bolt):
od = 3 # nominal
od_fit_bolt_3dp_pla = 3.3 # TESTED
od_fit_bolt_cnc = 3.3 # UNTESTED
od_fit_bolt_3dp_resin = 3.2 # TESTED
def __init__(self, l=6):
self.l = l
Regarding clean and reset, I have a rather wild proposal: use indentation. I indent my code like this anyway, because it helps me keep ideas sorted out. I've noticed that .clean() and .reset() always come just before the next re-indentation. I know that this is kind of an extreme approach, but look at this code - each .reset() and .clean() could be removed:
def teardrop2d(d=18, w=None, fillet=None, l=None, gap=.5):
w = w or d/4
fillet = fillet or d/3
l = d/2
return (
cq.Sketch()
.circle(d/2)
.push([(0, d/2)])
.rect(w, l*2)
.reset()
.clean()
.vertices('not(>Y)').fillet(fillet/2)
.clean()
.push([(0, d+gap)])
.rect(d, d, mode='s')
.clean()
.reset()
)
result = (
cq.Workplane()
.placeSketch(teardrop2d()).extrude(h)
# .faces('|Z').chamfer(0.5)
)
Alternatively, I was considering, for my own use,
making a plugin that would call both with .cr(). Conceptually, this
maps with the idea of a "carriage return" - it's somewhat like the
equivalent of a newline for a sketch.
Really, I think I would like to create a DSL. Get rid of all of the dots and parenthesis entirely, and replace them with newlines and indents. Get rid of the outer array parens on push. etc. Look how clean it could be. I've seen tools for making DSL's and wanted to try them before - no idea how difficult it is in practice. Would probably be nice/more achievable as a short term goal if you could drop back into python by starting a line with a special character - maybe just starting a line with a dot, which would be part of the python code anyway.