Misc-3D-Prints/Electronics and Digital Fabrication/relay_enclosure/temp.py

94 lines
2.2 KiB
Python
Raw Normal View History

import cadquery as cq
from cadquery import exporters
p_innerWidth = 27.0 # Outer width of box enclosure
p_innerLength = 51.0 # Outer length of box enclosure
p_innerHeight = 20 # Outer height of box enclosure
p_thickness = 1.0 # Thickness of the box walls
p_bottomHeight = 3
p_boardThickness = 1
p_screwpostSpacing = [20.4, 44.4]
p_screwpostID = 3.5
p_screwpostOD = 5
p_innerScrewpostOD = 6.25
p_screwLength = 12.0
p_countersinkDiameter = 5.75
p_hexnutDiameter = 6.5
p_hexnutDepth = 2.5
p_wireOpening = [15, 6]
countersinkDepth = (p_innerHeight + p_thickness * 2) - p_screwLength
enclosed = (
cq.Workplane("XY")
.rect(p_innerWidth, p_innerLength)
.extrude(p_innerHeight)
)
# split box into lid and bottom parts
(bottom, lid) = (
enclosed.shell(p_thickness)
.faces("<Z")
.workplane(-(p_thickness + p_bottomHeight + p_boardThickness))
.split(keepTop=True, keepBottom=True)
.all()
)
bottom = (
bottom.faces("<Z[1]").workplane()
.rect(*p_screwpostSpacing, forConstruction=True)
.vertices()
.polygon(6, p_hexnutDiameter + p_thickness * 2)
.extrude(p_bottomHeight)
)
bottom = (
bottom.faces("<Z").workplane()
.rect(*p_screwpostSpacing, forConstruction=True)
.vertices().tag("screw_holes")
.polygon(6, p_hexnutDiameter)
.cutBlind(-p_hexnutDepth)
.vertices(tag="screw_holes")
.circle(p_screwpostID / 2.0)
.cutThruAll()
)
lid = (
lid.faces("<Z").workplane()
.rect(*p_screwpostSpacing, forConstruction=True)
.vertices()
.circle(p_screwpostOD / 2.0)
.extrude('next')
)
lid = (
lid.faces(">Z").workplane()
.rect(*p_screwpostSpacing, forConstruction=True)
.vertices().tag("screw_holes")
.circle(p_countersinkDiameter / 2.0 + p_thickness)
.extrude(-(countersinkDepth + p_thickness))
.vertices(tag="screw_holes")
.cboreHole(p_screwpostID, p_countersinkDiameter, countersinkDepth)
)
lid = (
lid.faces(">Y").edges("<Z").workplane(centerOption='CenterOfMass')
.move(0, p_wireOpening[1] / 2.0)
.rect(*p_wireOpening)
.cutThruAll()
)
show_object(bottom, 'bottom')
show_object(lid, 'lid')
exporters.export(bottom, f'bottom.stl')
exporters.export(lid, f'lid.stl')