opel-cad/opel_pin.py
2026-06-26 11:36:45 +02:00

76 lines
No EOL
2.8 KiB
Python

from build123d import *
from ocp_vscode import show
# ==========================================
# --- MASTER PARAMETER ---
# Defines the outer diameter in mm.
# Change this single value to scale the entire model!
model_size = 35.0
# ==========================================
# --- Derived Parameters ---
# All dimensions are calculated as fractions of the original 35mm baseline
outer_diameter = model_size
inner_diameter = model_size * (29.0 / 35.0)
thickness = model_size * (2.0 / 35.0)
# Pin dimensions
pin_diameter = model_size * (2.0 / 35.0)
pin_length = model_size * (5.0 / 35.0)
pin_spacing = model_size * (14.0 / 35.0) # Distance from center to each pin
# --- Lightning Bolt Proportions ---
# W is a safe overhang width (guaranteed to be outside the ring for clean intersection)
W = outer_diameter * 1.2
# Vertical (Y) heights for the horizontal bars
y_top_outer = model_size * (4.0 / 35.0)
y_top_inner = model_size * (2.0 / 35.0)
y_bot_outer = model_size * (-4.0 / 35.0)
y_bot_inner = model_size * (-2.0 / 35.0)
# Horizontal (X) positions mapping the central diagonal cut
x_inner_left = model_size * (-2.0 / 35.0)
x_diag_bot = model_size * (-6.0 / 35.0)
x_inner_right = model_size * (2.0 / 35.0)
x_diag_top = model_size * (6.0 / 35.0)
with BuildPart() as opel_pin:
# 1. Base Ring
with BuildSketch() as ring_sketch:
Circle(outer_diameter / 2)
Circle(inner_diameter / 2, mode=Mode.SUBTRACT)
extrude(amount=thickness)
# 2. Lightning Bolt Profile (Fully Parametric)
with BuildSketch() as bolt_sketch:
# Drawing the Z-shape using our dynamic variables
pts = [
(-W, y_top_outer), # 1. Top-left outer edge
(-W, y_bot_inner), # 2. Bottom-left outer edge
(x_inner_left, y_bot_inner), # 3. Inner bottom-left corner
(x_diag_bot, y_bot_outer), # 4. Diagonal drop to the lower bar
(W, y_bot_outer), # 5. Bottom-right outer edge
(W, y_top_inner), # 6. Top-right outer edge
(x_inner_right, y_top_inner), # 7. Inner top-right corner
(x_diag_top, y_top_outer) # 8. Diagonal rise back to the upper bar
]
Polygon(*pts)
# Cleanly slice off the overhangs using the outer circle
Circle(outer_diameter / 2, mode=Mode.INTERSECT)
extrude(amount=thickness)
# 3. Mounting Pins (on the back face)
bottom_face = opel_pin.faces().sort_by(Axis.Z)[0]
with BuildSketch(bottom_face) as pin_sketch:
# Place pins dynamically based on the scale
with Locations((-pin_spacing, 0), (pin_spacing, 0)):
Circle(pin_diameter / 2)
extrude(amount=pin_length)
# --- Send to OCP CAD Viewer ---
show(opel_pin)