diff --git a/src/core.py b/src/core.py index 10d302a..ffcfe43 100644 --- a/src/core.py +++ b/src/core.py @@ -15,7 +15,7 @@ # Prepare the stem_wrapper with BuildPart() as stem_wrapper: with BuildSketch(Plane.front): # as cross_section - RectangleRounded(stem_width + 2 * wall, stem_height + 2 * wall, wall) + RectangleRounded(stem_width + 2 * wall, stem_height + 2 * wall, wall/2 - eps) RectangleRounded(stem_width, stem_height, stem_fillet - wall, mode=Mode.SUBTRACT) extrude(amount=stem_length/2, both=True) fillet(faces().filter_by(Plane.XY).edges(), wall/2 - eps) @@ -25,7 +25,7 @@ # Prepare the screw hole adapter screw_hole_base = ScrewableCylinder() bb = screw_hole_base.bounding_box() -eps_offset_loft = 0.01 +eps_offset_loft = 0.1 # Causes broken geometry if too small RigidJoint("left", screw_hole_base, Location((bb.min.X - eps_offset_loft, bb.center().Y, bb.center().Z), (0, 90, 0))) with BuildPart() as core: @@ -46,24 +46,27 @@ del loft_screw_hole_face, loft_stem_face, screw_hole_base # Make it 3D printable by adding top and bottom supports - for face_side in [-1, 1]: # Top and bottom - face = faces().group_by(Axis.Z)[0 if face_side < 0 else -1].face() + for face_side in [-1, 1]: # Bottom and top + face_search = 0 if face_side < 0 else -1 + face = faces().group_by(Axis.Z)[face_search].face() extreme = stem_wrapper.bounding_box().min if face_side < 0 else stem_wrapper.bounding_box().max - extreme.Z += face_side * -(wall - eps_offset_loft*10) # Ignore fillet + extreme.Z -= face_side * wall/2 # Ignore fillet max_extrude = face.center().Z - extreme.Z extrude(face, amount=abs(max_extrude)) assert core.part.is_valid() del extreme # Prepare a cut plane max_offset = face.bounding_box().size.X - cut_plane_angle = degrees(atan2(max_offset, max_extrude)) + cut_plane_angle = degrees(atan2(max_extrude, max_offset)) print(cut_plane_angle) bb = face.bounding_box() cut_plane = Plane(Location((bb.max.X, bb.center().Y, bb.center().Z), (0, -cut_plane_angle, 0))) - split(bisect_by=cut_plane, keep=Keep.TOP) + split(bisect_by=cut_plane, keep=Keep.TOP if face_side < 0 else Keep.BOTTOM) assert core.part.is_valid() assert len(core.part.solids()) == 1 del face, cut_plane + # Fillet some edges of supports + fillet(faces().group_by(Axis.Z)[face_search].edges() - edges().group_by(Axis.X)[0], wall/2.01) # Mirror to the other side mirror(about=Plane.YZ) diff --git a/src/screwable_cylinder.py b/src/screwable_cylinder.py index 13bb1f1..c070789 100644 --- a/src/screwable_cylinder.py +++ b/src/screwable_cylinder.py @@ -10,7 +10,7 @@ @dataclass(kw_only=True) class ScrewableCylinder(BasePartObject): - screw_length: float = 8 + screw_length: float = 12 screw_diameter: float = 5 # M5 screw_head_diameter: float = 8.5 # M5 screw_head_height: float = 5 # M5