Skip to content
Development version. Forge is under active development and testing. APIs, behaviour, coverage and verification results may be incomplete or change without notice; published PASS results are not a support guarantee or production-readiness claim.

Geometry, sketches and Boolean operations

Start with a solid

Box, Cylinder and Sphere are centred on their geometric CENTER by default. Use anchor=... when a face, axial end or tangent datum should lie at the origin. For Cylinder the anchor is resolved after choosing Axis.X, Axis.Y or Axis.Z; for example LEFT/RIGHT are the axial ends of an X-axis cylinder and BOTTOM/TOP are the axial ends of a Z-axis cylinder.

from scpf import (
    BOTTOM, FRONT, LEFT, RIGHT,
    Axis, Box, Cylinder, Sphere,
)

plate = Box(80, 50, 8)
board = Box(80, 50, 12).at(
    0, 0, 0,
    anchor=FRONT + BOTTOM,
).fillet(
    4,
    edges=[BOTTOM + LEFT, BOTTOM + RIGHT],
)
pin = Cylinder(d=8, h=20, axis=Axis.Z).at(
    10, 10, 8,
    anchor=BOTTOM,
)
side_pin = Cylinder(d=8, h=20, axis=Axis.X).at(-10, 0, 0)
ball = Sphere(12)

body = Sphere(20) & Box(30, 30, 30)
centered_bore = Cylinder(d=8, h=30, axis=Axis.X).at(body)

at(x, y, z) places CENTER at those coordinates unless another anchor=... is supplied. Passing another Shape instead uses shape-relative CENTER-to-CENTER placement. Forge derives the native Box corner, Cylinder base or Sphere center from the selected datum; callers do not add manual half-size corrections.

Draw a 2D profile, then extrude it

A Rectangle2D is a planar profile rather than a 3D body. 2D geometry is authored inside an explicit Sketch scope. Polygon2D can be created on the XY, XZ or YZ plane.

from scpf import Sketch, Rectangle2D, Polygon2D

with Sketch(plane="XY") as plate_sketch:
    Rectangle2D(80, 50)
plate = plate_sketch.extrude(8)

with Sketch(plane="XZ") as side_sketch:
    Polygon2D(
        [(0, 0), (40, 0), (40, 8), (8, 8), (8, 30), (0, 30)],
        plane="XZ",
        world=True,
    )
side = side_sketch.extrude(10)

# Signed distance chooses the side of the sketch plane.
backward = plate_sketch.extrude(-8)
centered = plate_sketch.extrude(8, sym=True)

A sketch plane affects where its axes go; changing the camera does not rotate its geometry. Leave the with Sketch(...) scope, then call sketch.extrude(...) to create 3D material. A positive distance follows the sketch-plane normal, a negative distance goes the other way, and sym=True divides a positive distance equally over both sides. Direct Rectangle2D(...).extrude(...) syntax is intentionally not supported.

Polygon2D works in standalone explicit Sketches and in face-attached explicit Sketches; its authored vertices stay sketch-local. Standalone Sketches may also use an explicit origin= and rotation=(rx, ry, rz). An extrusion from that rotated local frame can participate directly in +, - or & CSG, including non-axis-aligned cutters.

Select profiles when extruding a Sketch

By default Sketch.extrude() uses every closed profile in the Sketch. Use profiles=[(x, y), ...] when only some closed regions should be extruded or cut. The points are fixed coordinates in the Sketch itself; users do not need SolidCraft profile indices or curve ids.

from scpf import Anchor, Axis, Box, Circle2D, Depth, Sketch

board = Box(120, 80, 5, anchor=Anchor.BOTTOM)
with Sketch(name="Selected holes", on=board, parent=Anchor.TOP) as holes:
    seed = holes.add(Circle2D(d=8), offset=(-30, 0))
    holes.rectangular_pattern(
        seed,
        count=4,
        spacing=20,
        direction=Axis.X,
    )

board = board - holes.extrude(
    Depth.THROUGH_ALL,
    profiles=[(-30, 0), (-10, 0), (30, 0)],
    exact_regions=True,
)

SolidCraft 0.42 stores a successful point selection using the curves around the selected profile where possible. That lets the selection follow the profile when the saved design recomputes. exact_regions=True asks SolidCraft to use exactly the region containing each point. Profile points must be fixed finite numbers; Forge Parameters and expressions are not accepted in this field.

A standalone Sketch may contain several closed loops. Nested loops remain one native Sketch; select the intended exact region when the loops create more than one region. A hollow tube can therefore be authored as one concentric two-circle Sketch and one extrusion:

with Sketch(name="Tube profile", plane="XY") as profile:
    Circle2D(d=10)
    Circle2D(d=8)

tube = profile.extrude(
    30,
    profiles=[(4.5, 0)],
    exact_regions=True,
)

This capability is specific to extrusion. Sketch.revolve() still requires exactly one closed profile.

Repeat and mirror profiles inside one Sketch

Sketch.rectangular_pattern() makes a native SolidCraft sketch pattern from a profile that already belongs to the Sketch. Sketch.mirror() mirrors a profile, a pattern result or an earlier mirror result. Both methods return a Sketch result that can be passed to another supported Sketch operation.

from scpf import Anchor, Axis, Box, Circle2D, Depth, Sketch

board = Box(200, 120, 8)
with Sketch(name="Dog holes", on=board, parent=Anchor.TOP) as holes:
    seed = holes.add(Circle2D(d=8), offset=(-40, 20))
    row = holes.rectangular_pattern(
        seed,
        count=4,
        spacing=25,
        direction=Axis.X,
    )
    holes.mirror(row, axis=Axis.X)

board = board - holes.extrude(Depth.THROUGH_ALL)

The same operations work with native Slot profiles. A pattern or mirror result can be used as the source of the next operation.

from scpf import Anchor, Axis, Sketch, SlotCenterToCenter2D

with Sketch(name="Clamp slots", on=board, parent=Anchor.TOP) as slots:
    seed = SlotCenterToCenter2D((20, 20), (40, 20), 8)
    arm = slots.rectangular_pattern(
        seed,
        count=2,
        spacing=50,
        direction=Axis.X,
    )
    opposite = slots.mirror(arm, axis=Axis.Y)
    slots.mirror(arm, axis=Axis.X)
    slots.mirror(opposite, axis=Axis.X)

count, count2, spacing and spacing2 may use suitable model Parameters, so those values remain editable in the saved SolidCraft design. Current native qualification covers attached Sketch(on=...) use. Pattern directions support Axis.X, Axis.Y or a fixed 2D vector. Mirrors currently support the Sketch X or Y origin axis. Per-instance pattern suppression is not supported.

SolidCraft 0.42 stores the curves selected when a mirror is created. If a pattern later creates extra curves after its count changes, those new curves are not added to that existing mirror automatically.

Add, subtract and intersect

body = Box(50, 50, 20)
tool = Cylinder(d=12, h=22).at(0, 0, 0)
joined = body + tool       # union, where supported
cut = body - tool          # difference, where supported
shared = body & tool       # intersection, where supported

The supported compiler path depends on the operands. Native feature history and CSG trees are not interchangeable for every operation. For manufacturing features such as holes, prefer the native feature operations.

Configuration tables

Use Configure on the completed design to author an editable native table. The design may be a Shape or an assembly result. Param selects an existing native model parameter; Suppress selects an exact applied Forge feature. Each named row contains one cell per column. The active row must be declared.

Configure(plate - hole, active="Medium",
    columns=(Param(self.width), Suppress(hole)),
    rows={"Medium": ("80 mm", True),
          "Large": ("100 mm", False)})

The native table remains editable in the saved SolidCraft document. Forge’s own configuration-table model qualifies the public contract; downstream CAD models consume the released API rather than serving as its implementation fixture.

Assembly positions

Configuration rows can drive any associative parameter dependency. For an assembly this includes occurrence placement, so useful positions such as front, below and service stay in the same native table rather than becoming Python variants.

return Configure(display, active="Front",
    columns=(Param("plate_y"), Param("plate_z")),
    rows={
        "Front": ("8 mm", "0 mm"),
        "Below": ("0 mm", "-55 mm"),
        "Service": ("25 mm", "0 mm"),
    })

Free and Installed states

For a flexible-fit part, use Free for the uninstalled manufacturing or print geometry and Installed for the mounted working geometry. These are physical configuration states, not render or display-state names.

return Configure(part, active="Free",
    columns=(Param(self.fit_diameter),),
    rows={
        "Free": ("20.4 mm",),
        "Installed": ("20.0 mm",),
    })

Keeping Free active makes the normal built artifact the manufacturing state. A presentation may later choose Installed, but that selection belongs to presentation tooling rather than the model API.

Shifted revolve axes

Use AxisLine when a native revolve must run around a line that does not pass through the world origin. Its origin coordinates may remain model parameters or expressions.

with Sketch(plane="XY", offset=self.pin_z) as profile:
    Polygon2D([...], plane="XY")

cut = profile.revolve(
    axis=AxisLine(
        Axis.Y,
        origin=(self.pin_x, 0, self.pin_z),
    ),
)
body = panel - cut

The axis line must be coplanar with the standalone Sketch. A parameter-driven Sketch offset and the matching AxisLine origin remain native SolidCraft expressions. The returned revolve is one feature and can therefore be passed to Suppress(cut).