From fe7f39bb7c92eb5c3867c32a664489755a9a13be Mon Sep 17 00:00:00 2001 From: Roger Maitland Date: Wed, 13 Jul 2022 16:16:48 -0400 Subject: [PATCH] Adding examples --- examples/canadian_flag.py | 45 +++++++++++++++++++++++++++++++++ examples/din_rail.py | 46 ++++++++++++++++++++++++++++++++++ examples/intersecting_pipes.py | 17 +++++++++++++ examples/pillow_block.py | 21 ++++++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 examples/canadian_flag.py create mode 100644 examples/din_rail.py create mode 100644 examples/intersecting_pipes.py create mode 100644 examples/pillow_block.py diff --git a/examples/canadian_flag.py b/examples/canadian_flag.py new file mode 100644 index 0000000..6df2943 --- /dev/null +++ b/examples/canadian_flag.py @@ -0,0 +1,45 @@ +from cadquery import Vector +from build123d_common import * +from build_line import * +from build_sketch import * + +with BuildSketch() as leaf: + with BuildLine() as outline: + l1 = Polyline((0.0000, 0.0771), (0.0187, 0.0771), (0.0094, 0.2569)) + l2 = Polyline((0.0325, 0.2773), (0.2115, 0.2458), (0.1873, 0.3125)) + RadiusArc(l1 @ 1, l2 @ 0, 0.0271) + l3 = Polyline((0.1915, 0.3277), (0.3875, 0.4865), (0.3433, 0.5071)) + TangentArc(l2 @ 1, l3 @ 0, tangent=l2 % 1) + l4 = Polyline((0.3362, 0.5235), (0.375, 0.6427), (0.2621, 0.6188)) + SagittaArc(l3 @ 1, l4 @ 0, 0.003) + l5 = Polyline((0.2469, 0.6267), (0.225, 0.6781), (0.1369, 0.5835)) + ThreePointArc(l4 @ 1, (l4 @ 1 + l5 @ 0) * 0.5 + Vector(-0.002, -0.002), l5 @ 0) + l6 = Polyline((0.1138, 0.5954), (0.1562, 0.8146), (0.0881, 0.7752)) + Spline(l5 @ 1, l6 @ 0, tangents=(l5 % 1, l6 % 0), tangent_scalars=(2, 2)) + l7 = Line((0.0692, 0.7808), (0.0000, 0.9167)) + TangentArc(l6 @ 1, l7 @ 0, tangent=l6 % 1) + MirrorToLine(*outline.edges(), axis=Axis.Y) + BuildFace(*leaf.pending_edges) + +with BuildSketch() as west_field: + PushPointsToSketch((-1, 0)) + Rectangle(0.5, 1, centered=(False, False)) + +with BuildSketch() as east_field: + MirrorToSketch(west_field.sketch, axis=Axis.Y) + +with BuildSketch() as centre_field: + Rectangle(1, 1, centered=(True, False)) + AddToSketch(leaf.sketch, mode=Mode.SUBTRACTION) + +if "show_object" in locals(): + show_object( + [west_field.sketch, east_field.sketch, leaf.sketch], + name="flag_red_parts", + options={"color": (255, 0, 0)}, + ) + show_object( + centre_field.sketch, + name="flag_white_part", + options={"color": (255, 255, 255)}, + ) diff --git a/examples/din_rail.py b/examples/din_rail.py new file mode 100644 index 0000000..a82d5c1 --- /dev/null +++ b/examples/din_rail.py @@ -0,0 +1,46 @@ +from ..build_part import * +from ..build_sketch import * + +# 35x7.5mm DIN Rail Dimensions +overall_width, top_width, height, thickness, fillet = 35, 27, 7.5, 1, 0.8 +rail_length = 1000 +slot_width, slot_length, slot_pitch = 6.2, 15, 25 + +with BuildPart(workplane=Plane.named("XZ")) as rail: + with BuildSketch() as din: + Rectangle(overall_width, thickness, centered=(True, False)) + Rectangle(top_width, height, centered=(True, False)) + Rectangle( + top_width - 2 * thickness, + height - thickness, + centered=(True, False), + mode=Mode.SUBTRACTION, + ) + inside_vertices = ( + din.vertices() + .filter_by_position(Axis.Y, 0.0, height, inclusive=(False, False)) + .filter_by_position( + Axis.X, + -overall_width / 2, + overall_width / 2, + inclusive=(False, False), + ) + ) + FilletSketch(*inside_vertices, radius=fillet) + outside_vertices = list( + filter( + lambda v: (v.Y == 0.0 or v.Y == height) + and -overall_width / 2 < v.X < overall_width / 2, + din.vertices(), + ) + ) + FilletSketch(*outside_vertices, radius=fillet + thickness) + Extrude(rail_length) + WorkplanesFromFaces(rail.faces().filter_by_normal(Axis.Z)[-1], replace=True) + with BuildSketch() as slots: + RectangularArrayToSketch(0, slot_pitch, 1, rail_length // slot_pitch - 1) + SlotOverall(slot_length, slot_width, rotation=90) + slot_holes = Extrude(-height, mode=Mode.SUBTRACTION) + +if "show_object" in locals(): + show_object(rail.part, name="rail") diff --git a/examples/intersecting_pipes.py b/examples/intersecting_pipes.py new file mode 100644 index 0000000..d2dd292 --- /dev/null +++ b/examples/intersecting_pipes.py @@ -0,0 +1,17 @@ +from build_part import * +from build_sketch import * + +with BuildPart() as pipes: + Box(10, 10, 10, rotation=(10, 20, 30)) + WorkplanesFromFaces(*pipes.faces(), replace=True) + with BuildSketch() as pipe: + Circle(4) + Extrude(-5, mode=Mode.SUBTRACTION) + with BuildSketch() as pipe: + Circle(4.5) + Circle(4, mode=Mode.SUBTRACTION) + Extrude(10) + FilletPart(*pipes.edges(Select.LAST), radius=0.2) + +if "show_object" in locals(): + show_object(pipes.part, name="intersecting pipes") diff --git a/examples/pillow_block.py b/examples/pillow_block.py new file mode 100644 index 0000000..e452c4a --- /dev/null +++ b/examples/pillow_block.py @@ -0,0 +1,21 @@ +from build_sketch import * +from build_part import * + +height, width, thickness, padding = 60, 80, 10, 12 +screw_shaft_radius, screw_head_radius, screw_head_height = 1.5, 3, 3 +bearing_axle_radius, bearing_radius, bearing_thickness = 4, 11, 7 + +# Build pillow block as an extruded sketch with counter bore holes +with BuildPart() as pillow_block: + with BuildSketch() as plan: + Rectangle(width, height) + FilletSketch(*plan.vertices(), radius=5) + Extrude(thickness) + WorkplanesFromFaces(pillow_block.faces().filter_by_normal(Axis.Z)[-1]) + CounterBoreHole(bearing_axle_radius, bearing_radius, bearing_thickness) + RectangularArrayToPart(width - 2 * padding, height - 2 * padding, 2, 2) + CounterBoreHole(screw_shaft_radius, screw_head_radius, screw_head_height) + +# Render the part +if "show_object" in locals(): + show_object(pillow_block.part)