Refactor parameters for consistency and clarity; enhance pin and logo construction logic
This commit is contained in:
parent
aae3add1a6
commit
627e136b42
1 changed files with 57 additions and 43 deletions
98
opel_pin.py
98
opel_pin.py
|
|
@ -4,28 +4,56 @@ from ocp_vscode import show
|
|||
# ==========================================
|
||||
# --- MASTER PARAMETERS ---
|
||||
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 ---
|
||||
outer_diameter = model_size
|
||||
inner_diameter = model_size * (25.4 / model_size)
|
||||
thickness = model_size * (2.3 / model_size)
|
||||
inner_diameter = model_size * (25.4 / 31.0)
|
||||
thickness = model_size * (2.3 / 31.0)
|
||||
|
||||
pin_diameter = model_size * (3.1 / model_size)
|
||||
pin_length = model_size * (10.8 / model_size)
|
||||
pin_spacing = model_size * (14.0 / model_size)
|
||||
pin_height_offset = model_size * (1.55 / model_size)
|
||||
fillet_radius = model_size * (0.15 / model_size)
|
||||
pin_diameter = model_size * (3.1 / 31.0)
|
||||
pin_length = model_size * (10.8 / 31.0)
|
||||
pin_spacing = model_size * (14.0 / 31.0)
|
||||
pin_height_offset = model_size * (1.55 / 31.0)
|
||||
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 ---
|
||||
W = (outer_diameter / 2) + overhang
|
||||
bound = model_size
|
||||
H_outer = model_size * (3.1 / model_size)
|
||||
H_inner = model_size * (0.5 / model_size)
|
||||
X_point = model_size * (5.8 / model_size)
|
||||
X_inner = model_size * (2.7 / model_size)
|
||||
H_outer = model_size * (3.1 / 31.0)
|
||||
H_inner = model_size * (0.5 / 31.0)
|
||||
X_point = model_size * (5.8 / 31.0)
|
||||
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:
|
||||
# 1. Base Ring
|
||||
with BuildSketch() as ring_sketch:
|
||||
|
|
@ -36,47 +64,33 @@ with BuildPart() as opel_pin:
|
|||
# 2. Lightning Bolt Profile (Aggressive Z-Shape)
|
||||
with BuildSketch() as bolt_sketch:
|
||||
pts = [
|
||||
(-bound, H_outer), # 1. Top-left outer edge
|
||||
(-bound, -H_inner), # 2. Bottom-left outer edge of upper bar
|
||||
(-X_inner, -H_inner), # 3. Inner bottom corner (cuts right, past center)
|
||||
(-X_point, -H_outer), # 4. Sharp bottom-left point (diagonals back left)
|
||||
(bound, -H_outer), # 5. Bottom-right outer edge
|
||||
(bound, H_inner), # 6. Top-right outer edge of lower bar
|
||||
(X_inner, H_inner), # 7. Inner top corner (cuts left, past center)
|
||||
(X_point, H_outer) # 8. Sharp top-right point (diagonals back right)
|
||||
(-bound, H_outer),
|
||||
(-bound, -H_inner),
|
||||
(-X_inner, -H_inner),
|
||||
(-X_point, -H_outer),
|
||||
(bound, -H_outer),
|
||||
(bound, H_inner),
|
||||
(X_inner, H_inner),
|
||||
(X_point, H_outer)
|
||||
]
|
||||
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)
|
||||
|
||||
# Cleanly slice off the overhangs
|
||||
Circle(W, mode=Mode.INTERSECT)
|
||||
extrude(amount=thickness)
|
||||
|
||||
# ==========================================
|
||||
# ---> THE FIX: Fillet ALL top edges <---
|
||||
# 1. Grab the highest face on the Z-axis (the newly merged face of both ring + bolt)
|
||||
# 3. Fillet ALL top edges
|
||||
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)
|
||||
# 4. Attach the Studded Mounting Pins
|
||||
# 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 Locations((-pin_spacing, pin_height_offset, -pin_length / 2),
|
||||
(pin_spacing, -pin_height_offset, -pin_length / 2)):
|
||||
add(master_pin.part)
|
||||
# ==========================================
|
||||
|
||||
# 3. Mounting Pins (on the back face)
|
||||
bottom_face = opel_pin.faces().sort_by(Axis.Z)[0]
|
||||
|
||||
with BuildSketch(bottom_face) as pin_sketch:
|
||||
with Locations((-pin_spacing, -pin_height_offset), (pin_spacing, pin_height_offset)):
|
||||
Circle(pin_diameter / 2)
|
||||
|
||||
extrude(amount=pin_length)
|
||||
|
||||
# --- 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")
|
||||
|
||||
# --- Send to OCP CAD Viewer ---
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue