The dxfwrite one looks promising!
And yes, I think it could work as a library. In fact, I’m planning on writing one
Here’s my sample code from last night. I had a couple drinks before hand, so try not to judge too harshly…
#! /usr/bin/env python
# -*- coding: UTF-8 -*-
from __future__ import division
import os
import sys
import re
# Assumes SolidPython is in site-packages or elsewhwere in sys.path
from solid import *
from solid.utils import *
SEGMENTS = 90
def tabs(height,width,depth,cutDiameter,count,closeSides=True):
singleTab = hull()(
cube([width/count,depth,height-cutDiameter/2]),
translate([cutDiameter/2,0,height-cutDiameter/2])(
rotate([-90,0,0])(cylinder(cutDiameter/2,depth))
),
translate([width/count-cutDiameter/2,0,height-cutDiameter/2])(
rotate([-90,0,0])(cylinder(cutDiameter/2,depth))
)
)
d = right(cutDiameter/2)(
cube([width-cutDiameter,depth,height-cutDiameter])
)
neg = cube([0,0,0])
for i in range(count):
if i % 2 == 0:
d += right(i*width/count)(singleTab)
else:
d -= up(height)(
right((i+1)*width/count)(
rotate([0,180,0])(singleTab)
)
)
if closeSides:
if (count % 2 == 0):
d += cube([cutDiameter/2,depth,height])
d -= right(width-cutDiameter/2)(
cube([cutDiameter/2,depth,height])
)
else:
d += cube([cutDiameter/2,depth,height])
d += right(width-cutDiameter/2)(
cube([cutDiameter/2,depth,height])
)
return d
def assembly():
sideHeight = 200
sideWidth = 100
ply = 0.47 * 25.4
topWidth = 150
tabHeight = 8
tabCount = 11
cutterDiameter = 3.125
sidePanel = cube([sideWidth,ply,sideHeight-ply]);
sidePanel += up(sideHeight-ply)(
tabs(tabHeight, sideWidth, ply, cutterDiameter, tabCount)
)
leftPanel = right(ply)(
rotate([0,0,90])(sidePanel)
)
rightPanel = right(topWidth)(
rotate([0,0,90])(sidePanel)
)
top = up(sideHeight-ply)(
cube([topWidth,sideWidth, ply])
)
top -= leftPanel
top -= rightPanel
return leftPanel + rightPanel
if __name__ == '__main__':
a = assembly()
scad_render_to_file(a, file_header='$fn = %s;' % SEGMENTS, include_orig_code=True)