Skip to content

Instantly share code, notes, and snippets.

@lf94
Created January 16, 2024 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lf94/b09ea73281a6497f403c4da53fb8ad4a to your computer and use it in GitHub Desktop.
Save lf94/b09ea73281a6497f403c4da53fb8ad4a to your computer and use it in GitHub Desktop.
weird.py
import cadquery as cq
# Parameters for the cylinder
cylinder_height = 50.0
cylinder_radius = 20.0
# Parameters for the rectangular cutouts
cutout_width = 5.0
cutout_height = 10.0
cutout_depth = 10.0
# Create the base cylinder
cylinder = cq.Workplane("XY").cylinder(cylinder_height, cylinder_radius)
# Define a function to create a single rectangular cutout
def make_cutout(workplane, width, height, depth, offset_angle):
# Create a rectangular prism for the cutout
cutout = (
workplane
.workplane(offset=cylinder_height/2 - depth/2)
.transformed(rotate=(0, 0, offset_angle))
.center(cylinder_radius, 0)
.rect(width, height)
.extrude(depth, True)
)
return cutout
# Create four cutouts at 0, 90, 180, and 270 degrees
for angle in range(0, 360, 90):
cutout = make_cutout(cq.Workplane("XY"), cutout_width, cutout_height, cutout_depth, angle)
cylinder = cylinder.cut(cutout)
# Final result
result = cylinder
# Export the result to a STEP file
cq.exporters.export(result, "/tmp/bed89d2d-cdf2-4d0b-9879-4740a28f732c.step")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment