FoundationPartsOperations3D curves & sketch Use

3D curves & sketch Use

A 3D curve (Path3D) is a Sweep / MultiSectionSweep path, a Loft guide rail, or a FillSurface / BoundarySurface boundary. Besides Spline3D and Helix3D, four curves are built from other geometry:

NodeCurve
CompositeCurve(curves)several curves chained end to end into one path (any order or direction)
IntersectionCurve(first, second)where two bodies meet: solids or surfaces, in any mix
IsoparametricCurve(surface, direction=U, at=0.5, face_finder=None)a constant-U / constant-V line across a face of a sheet
ProjectedCurve(curve, plane, direction=None)a curve projected onto a plane, along its normal or along direction
  • CompositeCurve: the pieces must touch end to end (within 0.001 mm); a gap is an error naming where the chain stops.
  • IntersectionCurve: the result must be one connected curve (a closed loop or an open one). Two cylinders’ sketches extruded as surfaces (ExtrudedSurface) and intersected give Onshape’s “projected curve from two sketches”.
  • IsoparametricCurve: at is the fraction of the face’s parameter range (0 = one edge, 1 = the opposite one). On a sheet with several faces (a full tube has two half-cylinders), pick one with face_finder.
  • ProjectedCurve is exact: lines stay lines, a circle parallel to the plane stays a circle, a tilted circle becomes the ellipse it casts.
ring = Sweep(Circle(Sketch(self.xz()).origin, 1.5), IntersectionCurve(ball, tube))
rod = Sweep(Circle(Sketch(self.xz()).origin, 2), IsoparametricCurve(sheet, IsoDirection.V, 0.5))
shadow = ProjectedCurve(Helix3D(6, 6, 8, Point3D(0, 0, 3), Point3D(0, 0, 1)), self.xy())

Not available: projecting a curve onto a curved face (the OpenCascade build in the kernel lacks the projection algorithm; only planes are supported), and offsetting a curve within a face.

Sketch “Use”: model edges in a sketch

ProjectedEdges(sketch, body, edge_finder=None) projects edges of a body (solid or surface) into a sketch, along the sketch normal, as sketch geometry: use it as an Extrusion / Lathe profile (closed) or a SurfaceLoft section (open).

  • edge_finder picks the edges; without it every edge is used. Edges that land on the same curve count once (a box’s top and bottom outlines), and edges seen end-on are dropped (its vertical edges).
  • The edges must chain into one outline or one open chain.
  • Draw it on a sketch other than the body’s own (the lid above uses a sketch 14 mm up).
box = Extrusion(Rectangle.from_center_and_sides(Sketch(self.xy()).origin, 24, 14), 8)
lid = Extrusion(ProjectedEdges(Sketch(self.xy().get_parallel_plane(14)), box), 2)

Sketch mirror is a sketch helper, mirror(shape, line): see Sketch operations.

from cadbuildr.foundation import *


class RingedBall(Part):
    """IntersectionCurve: where a R20 ball meets a r12 tube, a 1.5 mm ring is swept."""

    def __init__(self):
        s = Sketch(self.xy())
        ball = Sphere(s.origin, 20)
        tube = ExtrudedSurface(Circle(s.origin, 12), 40)
        ring = Sweep(
            Circle(Sketch(self.xz()).origin, 1.5), IntersectionCurve(ball, tube)
        )
        self.add_operation(ball)
        self.add_operation(ring)
        self.translate([-50, 0, 0])
        self.paint("light_blue")


class Arch(Part):
    """IsoparametricCurve: the mid-height line of a half tube, swept into an arch rod."""

    def __init__(self):
        s = Sketch(self.xy())
        half = CustomOpenShape(
            [Arc(Point(s, 12, 0), Point(s, 0, 12), Point(s, -12, 0))]
        )
        sheet = ExtrudedSurface(half, 20)
        mid = IsoparametricCurve(sheet, IsoDirection.V, 0.5)
        self.add_operation(Sweep(Circle(Sketch(self.xz()).origin, 2), mid))
        self.paint("dark_orange")


class BoxAndLid(Part):
    """Sketch "Use": the box's outline projected into a sketch above it, extruded as a lid."""

    def __init__(self):
        box = Extrusion(
            Rectangle.from_center_and_sides(Sketch(self.xy()).origin, 24, 14), 8
        )
        above = Sketch(self.xy().get_parallel_plane(14))
        lid = Extrusion(ProjectedEdges(above, box), 2)
        self.add_operation(box)
        self.add_operation(lid)
        self.translate([50, 0, 0])
        self.paint("lime")


class MirroredBracket(Part):
    """Sketch mirror: an outline of lines and an arc, mirrored across the y axis."""

    def __init__(self):
        s = Sketch(self.xy())
        a, b, c, d = Point(s, 2, 0), Point(s, 16, 0), Point(s, 16, 6), Point(s, 2, 12)
        half = CustomClosedShape(
            [Line(a, b), Line(b, c), Arc(c, Point(s, 11, 11), d), Line(d, a)]
        )
        axis = Line(Point(s, 0, -1), Point(s, 0, 1))
        self.add_operation(Extrusion(half, 4))
        self.add_operation(Extrusion(mirror(half, axis), 4))
        self.translate([0, -45, 0])
        self.paint("light_bluish_gray")


class CurvesAndSketchUse(Assembly):
    def __init__(self):
        for part in (RingedBall(), Arch(), BoxAndLid(), MirroredBracket()):
            self.add_component(part)


show(CurvesAndSketchUse())