Refactor parameters for consistency and clarity; enhance pin and logo construction logic

This commit is contained in:
Till Schmidt 2026-07-12 11:49:01 +02:00
parent aae3add1a6
commit 627e136b42

View file

@ -4,28 +4,56 @@ from ocp_vscode import show
# ========================================== # ==========================================
# --- MASTER PARAMETERS --- # --- MASTER PARAMETERS ---
model_size = 31.0 # Outer diameter of the ring model_size = 31.0 # Outer diameter of the ring
overhang = model_size * (3.0 / model_size) # How many mm the bolt sticks out past the ring overhang = model_size * (3.0 / 31.0) # How many mm the bolt sticks out
# ========================================== # ==========================================
# --- Derived Parameters --- # --- Derived Parameters ---
outer_diameter = model_size outer_diameter = model_size
inner_diameter = model_size * (25.4 / model_size) inner_diameter = model_size * (25.4 / 31.0)
thickness = model_size * (2.3 / model_size) thickness = model_size * (2.3 / 31.0)
pin_diameter = model_size * (3.1 / model_size) pin_diameter = model_size * (3.1 / 31.0)
pin_length = model_size * (10.8 / model_size) pin_length = model_size * (10.8 / 31.0)
pin_spacing = model_size * (14.0 / model_size) pin_spacing = model_size * (14.0 / 31.0)
pin_height_offset = model_size * (1.55 / model_size) pin_height_offset = model_size * (1.55 / 31.0)
fillet_radius = model_size * (0.15 / model_size) fillet_radius = model_size * (0.15 / 31.0)
# --- Stud Parameters ---
stud_stickout = model_size * (0.4 / 31.0)
stud_thickness = model_size * (0.5 / 31.0)
# --- Lightning Bolt Proportions --- # --- Lightning Bolt Proportions ---
W = (outer_diameter / 2) + overhang W = (outer_diameter / 2) + overhang
bound = model_size bound = model_size
H_outer = model_size * (3.1 / model_size) H_outer = model_size * (3.1 / 31.0)
H_inner = model_size * (0.5 / model_size) H_inner = model_size * (0.5 / 31.0)
X_point = model_size * (5.8 / model_size) X_point = model_size * (5.8 / 31.0)
X_inner = model_size * (2.7 / model_size) X_inner = model_size * (2.7 / 31.0)
# ==========================================
# --- 1. BUILD THE MASTER PIN ---
# We build a single fully-studded pin first.
with BuildPart() as master_pin:
# Build the smooth base cylinder
Cylinder(radius=pin_diameter / 2, height=pin_length)
# We will place 3 rows of studs vertically along the pin
# We use 0.25 and -0.25 so the studs sit neatly along the middle shaft
z_offsets = [pin_length * 0.25, 0, -pin_length * 0.25]
for z in z_offsets:
with Locations((0, 0, z)):
# PolarLocations places local coordinate systems around a circle.
# It naturally rotates so the local "X" axis points directly outward!
with PolarLocations(radius=pin_diameter / 2, count=4):
# A box is drawn. Since we want it sticking out by "stud_stickout",
# we make its length exactly double that (half embeds into the pin, half sticks out)
Box(length=stud_stickout * 2, width=stud_thickness, height=stud_thickness)
# ==========================================
# ==========================================
# --- 2. BUILD THE OPEL LOGO ---
with BuildPart() as opel_pin: with BuildPart() as opel_pin:
# 1. Base Ring # 1. Base Ring
with BuildSketch() as ring_sketch: with BuildSketch() as ring_sketch:
@ -36,47 +64,33 @@ with BuildPart() as opel_pin:
# 2. Lightning Bolt Profile (Aggressive Z-Shape) # 2. Lightning Bolt Profile (Aggressive Z-Shape)
with BuildSketch() as bolt_sketch: with BuildSketch() as bolt_sketch:
pts = [ pts = [
(-bound, H_outer), # 1. Top-left outer edge (-bound, H_outer),
(-bound, -H_inner), # 2. Bottom-left outer edge of upper bar (-bound, -H_inner),
(-X_inner, -H_inner), # 3. Inner bottom corner (cuts right, past center) (-X_inner, -H_inner),
(-X_point, -H_outer), # 4. Sharp bottom-left point (diagonals back left) (-X_point, -H_outer),
(bound, -H_outer), # 5. Bottom-right outer edge (bound, -H_outer),
(bound, H_inner), # 6. Top-right outer edge of lower bar (bound, H_inner),
(X_inner, H_inner), # 7. Inner top corner (cuts left, past center) (X_inner, H_inner),
(X_point, H_outer) # 8. Sharp top-right point (diagonals back right) (X_point, H_outer)
] ]
z_shape = Polygon(*pts) z_shape = Polygon(*pts)
# Fillet the 2D corners of the Z shape so the inner zig-zag isn't infinitely sharp
fillet(z_shape.vertices(), radius=fillet_radius) fillet(z_shape.vertices(), radius=fillet_radius)
# Cleanly slice off the overhangs
Circle(W, mode=Mode.INTERSECT) Circle(W, mode=Mode.INTERSECT)
extrude(amount=thickness) extrude(amount=thickness)
# ========================================== # 3. Fillet ALL top edges
# ---> THE FIX: Fillet ALL top edges <---
# 1. Grab the highest face on the Z-axis (the newly merged face of both ring + bolt)
top_face = opel_pin.faces().sort_by(Axis.Z)[-1] top_face = opel_pin.faces().sort_by(Axis.Z)[-1]
fillet(top_face.edges(), radius=fillet_radius)
# 2. Grab ALL edges of that top face (no filtering)
all_top_edges = top_face.edges()
# 3. Apply the 3D fillet to the entire border
fillet(all_top_edges, radius=fillet_radius)
# ==========================================
# 3. Mounting Pins (on the back face) # 4. Attach the Studded Mounting Pins
bottom_face = opel_pin.faces().sort_by(Axis.Z)[0] # Because the logo extrudes upwards from Z=0, the back is perfectly flat at Z=0.
# We place our master_pin so its top (pin_length / 2) sits flush against the back.
with BuildSketch(bottom_face) as pin_sketch: with Locations((-pin_spacing, pin_height_offset, -pin_length / 2),
with Locations((-pin_spacing, -pin_height_offset), (pin_spacing, pin_height_offset)): (pin_spacing, -pin_height_offset, -pin_length / 2)):
Circle(pin_diameter / 2) add(master_pin.part)
# ==========================================
extrude(amount=pin_length)
# --- Export for 3D Printing --- # --- Export for 3D Printing ---
# This saves a STEP file in the same folder as your python script
export_step(opel_pin.part, "vintage_opel_pin.step") export_step(opel_pin.part, "vintage_opel_pin.step")
# --- Send to OCP CAD Viewer --- # --- Send to OCP CAD Viewer ---