Skip to content

Instantly share code, notes, and snippets.

@TobseF
Created April 5, 2026 22:01
Show Gist options
  • Select an option

  • Save TobseF/e712cb61e35a02e9b3e077f1e80c4b12 to your computer and use it in GitHub Desktop.

Select an option

Save TobseF/e712cb61e35a02e9b3e077f1e80c4b12 to your computer and use it in GitHub Desktop.
CadQery script for for a file holder
import cadquery as cq
# === Configuration & Parameters ===
# Dimensions of a single file (converted to mm)
file_width = 20.0
file_thickness = 4.35
file_height = 130.0
# Grid layout
grid_cols = 3
grid_rows = 2
# Tolerances and wall sizes
tolerance = 0.5 # Variable tolerance to give the files enough play
wall_thickness = 6.0 # Thickness of the walls separating the slots
bottom_thickness = 0.6
# Holder dimensions
# The holder doesn't need to be 130mm high, 35mm is usually enough to keep them upright
holder_height = 35.0
# Fillet radius
# Note: Must be smaller than bottom_thickness to prevent topology errors during filleting
corner_radius = 0.9
# Preview toggle for the files
show_files_preview = True
# === Calculations ===
# Calculate slot dimensions including the tolerance
slot_width = file_width + tolerance
slot_thickness = file_thickness + tolerance
slot_depth = holder_height - bottom_thickness
# Calculate center-to-center spacing for the grid
x_spacing = slot_width + wall_thickness
y_spacing = slot_thickness + wall_thickness
# Calculate total outer dimensions of the holder
holder_width = (grid_cols * slot_width) + ((grid_cols + 1) * wall_thickness)
holder_depth = (grid_rows * slot_thickness) + ((grid_rows + 1) * wall_thickness)
# === Modeling the Holder ===
# 1. Create the main base body
holder = cq.Workplane("XY").box(holder_width, holder_depth, holder_height)
# 2. Cut the 3x2 grid into the top face
holder = (
holder.faces(">Z")
.workplane()
.rarray(x_spacing, y_spacing, grid_cols, grid_rows)
.rect(slot_width, slot_thickness)
.cutBlind(-slot_depth)
)
# 3. Apply fillets to all edges to round off the corners
holder = holder.edges().fillet(corner_radius)
# === Modeling the Files (Preview) ===
if show_files_preview:
# Calculate the exact Z-height so the files rest on the 1mm bottom of the slots.
# The main box is centered at Z=0. The bottom face is at -(holder_height / 2).
# The slot floor is at -(holder_height / 2) + bottom_thickness.
file_z_center = - (holder_height / 2.0) + bottom_thickness + (file_height / 2.0)
files = (
cq.Workplane("XY")
.workplane(offset=file_z_center)
.rarray(x_spacing, y_spacing, grid_cols, grid_rows)
.box(file_width, file_thickness, file_height)
)
# === Visualization (for CQ-Editor) ===
# Render the holder in a solid color (e.g., a nice blue/grey)
if 'show_object' in globals():
show_object(holder, name="Holder", options={"color": (0.2, 0.4, 0.6, 0.0)})
# Render the files in a distinct, slightly transparent red if the preview is active
if show_files_preview:
show_object(files, name="Files_Preview", options={"color": (0.9, 0.2, 0.2, 0.6)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment