Skip to content

Instantly share code, notes, and snippets.

@jmwright
Created December 4, 2023 15:49
Show Gist options
  • Save jmwright/a15e11addd6eda20d72fb90719a062fc to your computer and use it in GitHub Desktop.
Save jmwright/a15e11addd6eda20d72fb90719a062fc to your computer and use it in GitHub Desktop.
CadScript ExSource Integration
exports:
rack_leg:
name: rack_leg
description: >
Rack Leg
output-files:
- ./rack_leg.stl
source-files:
- ./nimble_rack_leg.py
parameters:
length: 294 # mm
hole_spacing: 14 # mm
long_axis_hole_dia: 4.6 # mm
mounting_holes_dia: 3.6 # mm
application: cadquery
import cadscript as cad
length = 294
hole_spacing = 14
long_axis_hole_dia = 4.6
mounting_holes_dia = 3.6
def make_beam(length, hole_spacing, long_axis_hole_dia, mounting_holes_dia):
# Construct the overall shape
beam = cad.makeBox(20, 20, length)
beam = beam.fillet("|Z", 2.0)
# Long-axis hole for connecting multiple leg sections together
long_axis_hole = cad.makeSketch()
long_axis_hole.addCircle(long_axis_hole_dia / 2.0)
beam = beam.cutExtrude(">Z", long_axis_hole, -length)
# Channel cutouts
sketch = cad.makeSketch()
sketch.addPolygon([(-2.5, -1.5), (-5, 1.5), (5, 1.5), (2.5, -1.5)])
for angle in [0,90,180,270]:
s = sketch.copy().move([0,10]).rotate(angle)
beam.cutExtrude("<Z", s, -length)
# Mounting holes
mount_hole_ptn = cad.PatternRectArray(1, 14.0, 1, 21)
sketch = cad.makeSketch()
sketch.addCircle(mounting_holes_dia / 2.0, positions = mount_hole_ptn)
beam.cutExtrude("<Y", sketch, -20.0)
beam.cutExtrude("<X", sketch, -20.0)
return beam
# Handle different execution environments, including ExSource-Tools
beam = make_beam(length, hole_spacing, long_axis_hole_dia, mounting_holes_dia)
# beam.exportStl("beam.stl")
show_object(beam.cq())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment