Draft

Renders the 3D model in your browser. The first run downloads the Python runtime (≈30 MB).
import math

from cadbuildr.foundation import *


class TaperedBlock(Part):
    """Draft: every side wall leans in 5° going up from the XY (neutral) plane."""

    def __init__(self):
        s = Sketch(self.xy())
        block = Extrusion(Rectangle.from_center_and_sides(s.origin, 30, 20), 15)
        self.add_operation(Draft(block, 5))
        self.translate([-25, 0, 0])
        self.paint("light_blue")


class MouldedTray(Part):
    """Draft composes like any modifier: Shell(Draft(Extrusion)) gives a
    mould-friendly open tray with tapered walls."""

    def __init__(self):
        s = Sketch(self.xy())
        block = Extrusion(Rectangle.from_center_and_sides(s.origin, 30, 20), 15)
        self.add_operation(Shell(Draft(block, 8), 1.5))
        self.translate([25, 0, 0])
        self.paint("dark_orange")


class TiltedBoss(Part):
    """Draft about any plane: a boss on a sketch plane tilted 30° about X is
    drafted 6° about that plane (pull = the tilted plane's normal)."""

    def __init__(self):
        tilted = self.xy().get_angle_plane_from_axis(
            [1, 0, 0], math.radians(30), "tilted"
        )
        s = Sketch(tilted)
        boss = Extrusion(Rectangle.from_center_and_sides(s.origin, 20, 14), 12)
        self.add_operation(Draft(boss, 6, neutral_plane=tilted))
        self.translate([0, 35, 0])
        self.paint("light_green")


class DraftExamples(Assembly):
    def __init__(self):
        self.add_component(TaperedBlock())
        self.add_component(MouldedTray())
        self.add_component(TiltedBoss())


show(DraftExamples())

Draft(solid, angle_deg, neutral_plane_name="XY") tapers faces so a part can be pulled out of a mould or a casting. The faces keep their size on the neutral plane and lean inward by angle_deg going along the pull direction, which is that plane’s normal: "XY" pulls along +Z, "YZ" along +X, "XZ" along +Y.

To draft about any other plane, pass it as neutral_plane= (it overrides neutral_plane_name). The pull direction is that plane’s normal and faces keep their size where they cross it. The boss at the back stands on a sketch plane tilted 30° about X and is drafted about that same plane: Draft(boss, 6, neutral_plane=tilted).

By default every planar face parallel to the pull direction (all the side walls) is drafted. Pass edge_finder=FaceFinder(rule=…) to draft only some faces.

Draft composes like any other modifier. The tray on the right is Shell(Draft(Extrusion), 1.5): draft first, then hollow.

import math

from cadbuildr.foundation import *


class TaperedBlock(Part):
    """Draft: every side wall leans in 5° going up from the XY (neutral) plane."""

    def __init__(self):
        s = Sketch(self.xy())
        block = Extrusion(Rectangle.from_center_and_sides(s.origin, 30, 20), 15)
        self.add_operation(Draft(block, 5))
        self.translate([-25, 0, 0])
        self.paint("light_blue")


class MouldedTray(Part):
    """Draft composes like any modifier: Shell(Draft(Extrusion)) gives a
    mould-friendly open tray with tapered walls."""

    def __init__(self):
        s = Sketch(self.xy())
        block = Extrusion(Rectangle.from_center_and_sides(s.origin, 30, 20), 15)
        self.add_operation(Shell(Draft(block, 8), 1.5))
        self.translate([25, 0, 0])
        self.paint("dark_orange")


class TiltedBoss(Part):
    """Draft about any plane: a boss on a sketch plane tilted 30° about X is
    drafted 6° about that plane (pull = the tilted plane's normal)."""

    def __init__(self):
        tilted = self.xy().get_angle_plane_from_axis(
            [1, 0, 0], math.radians(30), "tilted"
        )
        s = Sketch(tilted)
        boss = Extrusion(Rectangle.from_center_and_sides(s.origin, 20, 14), 12)
        self.add_operation(Draft(boss, 6, neutral_plane=tilted))
        self.translate([0, 35, 0])
        self.paint("light_green")


class DraftExamples(Assembly):
    def __init__(self):
        self.add_component(TaperedBlock())
        self.add_component(MouldedTray())
        self.add_component(TiltedBoss())


show(DraftExamples())

Parting-line draft

A moulded part is usually split between two mould halves along a parting line, and its walls are drafted away from that line on both sides. PartingLineDraft(solid, angle_deg, parting_plane=…) does that: the walls keep their outline on the parting line and lean inward by angle_deg going up and going down from it.

parting = self.xy().get_parallel_plane(12)
self.add_operation(PartingLineDraft(body, 6, parting_plane=parting))
  • parting_plane= any Plane cutting the solid. Its normal is the pull direction.
  • parting_edges=EdgeFinder(…) instead: the parting line is the plane of the selected edge chain (e.g. the edges where a boss meets its flange, EdgeFinder(InPlaneFinderRule(self.xy(), 6))). The edges must lie in one plane. The pull direction is that plane’s normal, oriented towards +Z (or +Y, +X for vertical planes).
  • both_sides=False drafts only the side the pull direction points to; the other side stays straight.
  • face_finder=FaceFinder(…) picks the walls to draft (default: every planar face parallel to the pull direction).
Renders the 3D model in your browser. The first run downloads the Python runtime (≈30 MB).
from cadbuildr.foundation import *


class MouldedBlock(Part):
    """Parting-line draft: a 40 x 30 x 24 block whose walls keep their outline
    on the parting plane at z = 12 and taper 6 degrees above and below it
    (the part releases from a two-half mould)."""

    def __init__(self):
        s = Sketch(self.xy())
        body = Extrusion([Rectangle.from_center_and_sides(s.origin, 40, 30)], 24)
        parting = self.xy().get_parallel_plane(12)
        self.add_operation(PartingLineDraft(body, 6, parting_plane=parting))
        self.translate([-28, 0, 0])
        self.paint("light_blue")


class FlangedBoss(Part):
    """Parting-line draft about an edge chain: the edges where the boss meets
    its flange (z = 6) are the parting line; the flange tapers down, the boss
    tapers up."""

    def __init__(self):
        s = Sketch(self.xy())
        flange = Extrusion([Rectangle.from_center_and_sides(s.origin, 36, 28)], 6)
        boss = Extrusion([Rectangle.from_center_and_sides(s.origin, 26, 18)], 22, 6)
        body = BooleanOperation(flange, [boss], BooleanOp.UNION)
        parting_edges = EdgeFinder(InPlaneFinderRule(self.xy(), 6))
        self.add_operation(PartingLineDraft(body, 5, parting_edges=parting_edges))
        self.translate([28, 0, 0])
        self.paint("dark_orange")


class CornerSetback(Part):
    """Vertex chamfer (corner setback): every corner of the block is cut off
    4 mm along each of its three edges."""

    def __init__(self):
        s = Sketch(self.xy())
        self.extrude(Rectangle.from_center_and_sides(s.origin, 30, 30), 20)
        self.chamfer_vertices(4)
        self.translate([0, 45, 0])
        self.paint("lime")


class OneCorner(Part):
    """One picked corner, set back 8 mm (VertexChamfer on a feature)."""

    def __init__(self):
        s = Sketch(self.xy())
        body = Extrusion([Rectangle.from_center_and_sides(s.origin, 30, 30)], 20)
        self.add_operation(VertexChamfer(body, 8, vertices=[Point3D(15, -15, 20)]))
        self.translate([0, -45, 0])
        self.paint("light_blue")


class PartingDraftCorners(Assembly):
    def __init__(self):
        self.add_component(MouldedBlock())
        self.add_component(FlangedBoss())
        self.add_component(CornerSetback())
        self.add_component(OneCorner())


show(PartingDraftCorners())

The left block is drafted about a plane at mid-height. The orange part is drafted about the edge chain where its boss meets the flange: the flange tapers down, the boss tapers up.

Not supported: non-planar or stepped parting lines (a parting line that jumps between heights). OpenCascade’s parting-line draft builder (BRepOffsetAPI_MakeDraft) is not in this build. A parting plane that misses the solid, or parting edges that are not coplanar, give a processing error.

from cadbuildr.foundation import *


class MouldedBlock(Part):
    """Parting-line draft: a 40 x 30 x 24 block whose walls keep their outline
    on the parting plane at z = 12 and taper 6 degrees above and below it
    (the part releases from a two-half mould)."""

    def __init__(self):
        s = Sketch(self.xy())
        body = Extrusion([Rectangle.from_center_and_sides(s.origin, 40, 30)], 24)
        parting = self.xy().get_parallel_plane(12)
        self.add_operation(PartingLineDraft(body, 6, parting_plane=parting))
        self.translate([-28, 0, 0])
        self.paint("light_blue")


class FlangedBoss(Part):
    """Parting-line draft about an edge chain: the edges where the boss meets
    its flange (z = 6) are the parting line; the flange tapers down, the boss
    tapers up."""

    def __init__(self):
        s = Sketch(self.xy())
        flange = Extrusion([Rectangle.from_center_and_sides(s.origin, 36, 28)], 6)
        boss = Extrusion([Rectangle.from_center_and_sides(s.origin, 26, 18)], 22, 6)
        body = BooleanOperation(flange, [boss], BooleanOp.UNION)
        parting_edges = EdgeFinder(InPlaneFinderRule(self.xy(), 6))
        self.add_operation(PartingLineDraft(body, 5, parting_edges=parting_edges))
        self.translate([28, 0, 0])
        self.paint("dark_orange")


class CornerSetback(Part):
    """Vertex chamfer (corner setback): every corner of the block is cut off
    4 mm along each of its three edges."""

    def __init__(self):
        s = Sketch(self.xy())
        self.extrude(Rectangle.from_center_and_sides(s.origin, 30, 30), 20)
        self.chamfer_vertices(4)
        self.translate([0, 45, 0])
        self.paint("lime")


class OneCorner(Part):
    """One picked corner, set back 8 mm (VertexChamfer on a feature)."""

    def __init__(self):
        s = Sketch(self.xy())
        body = Extrusion([Rectangle.from_center_and_sides(s.origin, 30, 30)], 20)
        self.add_operation(VertexChamfer(body, 8, vertices=[Point3D(15, -15, 20)]))
        self.translate([0, -45, 0])
        self.paint("light_blue")


class PartingDraftCorners(Assembly):
    def __init__(self):
        self.add_component(MouldedBlock())
        self.add_component(FlangedBoss())
        self.add_component(CornerSetback())
        self.add_component(OneCorner())


show(PartingDraftCorners())