Components and assemblies
One definition, several occurrences
from scpf import Box, assembly, component
@component
class Beam:
length = 100.0
def build(self):
return Box(self.length, 20, 20)
@assembly
class BeamPair:
spacing = 120.0
def build(self):
left = Beam()
right = left.copy(placement=Placement(x=self.spacing))
return (left + right).group("Beams")
pair = BeamPair()@component marks one reusable physical part. Its build() returns the complete geometry/feature tree for that part; that tree may be made from many primitives and features. @assembly marks a class whose build() composes separate component occurrences. Both decorators return callable model objects, so normal model code stays readable as Beam() and BeamPair().
SolidCraft receives one reusable definition and multiple occurrences. A group is a native parent component in the browser, not a Boolean fusion of its children.
Component parameter visibility
Reusable component defaults are fixed by default. Publish selected child parameters explicitly with include=:
@component(include=("inside_corner_radius",))
class CornerBracket:
width = 24.0
inside_corner_radius = 4.0
def build(self):
...When a parent Parameter or expression is passed into a child input, that existing dependency stays symbolic. For example, CornerBracket(inside_corner_radius=self.corner_radius) reuses the parent design’s corner_radius; it does not create a separate CornerBracket_inside_corner_radius parameter.
Occurrence placement
copy() retains the source Placement when no override is supplied. copy(placement=Placement(...)) creates the new occurrence with the supplied absolute pose in the parent coordinate frame. The compiler uses creation-time copy translation where SolidCraft can represent it and a native fallback only where required.
center = BeamComponent()
array = center
for x in (-240, -120, 120, 240):
array = array + center.copy(placement=Placement(x=x))Component attachment
right = BeamComponent().attach(
left, parent=Anchor.RIGHT, child=Anchor.LEFT
)
marker = Marker().attach(
frame,
parent=Anchor.FRONT_TOP_RIGHT,
child=Anchor.BACK_TOP_RIGHT,
)attach() is the public Forge relationship between reusable components. Anchor selects the attachment reference: a supported face, or one of the eight rectangular corners such as FRONT_TOP_RIGHT. Corner anchors compile to native SolidCraft edge/corner origins, so they follow dimension changes in a saved design.
Associative in-plane attachment offset
attach(offset=(u, v)) moves the child within the attachment plane. Numeric values and parameter expressions are both supported. Forge lowers a non-zero or symbolic in-plane offset to a native planar joint and keeps u and v as SolidCraft joint values, so they are re-evaluated when their parameters change.
wood = Parameter("wood_thickness", 18)
bracket = Bracket().attach(
side,
parent=Anchor.FRONT_TOP_LEFT,
child=mount,
offset=(0, -wood + 12),
gap=-12,
)offset is independent of gap: the two offset values move in the attachment plane, while gap remains the normal distance between the two references. On a rectangular corner origin, the second planar value follows the selected vertical corner edge; its sign is defined by that corner frame rather than by world Z.
Assembly-owned named anchors
When a datum belongs to the meaning of an assembly rather than to a generic component, keep it on the assembly with with_anchor(). The anchor stores the target occurrence plus its attachment reference. Consumers resolve it by name with anchor().
frame = (left + right + bottom).with_anchor(
"front_top_left",
left,
AnchorTopology(
edge=(-6, 0, 181),
on=(0, 0, 181),
corner=(-6, 0, 362),
z=(0, 0, -1),
x=(1, 0, 0),
),
)
parent = frame.anchor("front_top_left")
bracket = CornerBracket().attach(
parent.target,
parent=parent.reference,
child=bracket_reference,
)This keeps a generic Board or CornerBracket free of application-specific anchor names while a higher-level frame can expose semantic datums such as front_top_left.
An assembly anchor may also carry its own symbolic offset=(u, v). Consumers can combine that semantic offset with a fixed local correction and pass the result to attach(offset=...). This is useful when an assembly datum follows a frame parameter such as wall thickness while the reusable part keeps a fixed mounting correction.
AnchorFrame: point plus orientation
An AnchorFrame describes one local attachment coordinate frame. origin gives the local point; z gives the attachment normal and x fixes the rotation around that normal. Use it when a single point or rectangular Anchor is not enough to describe how the occurrence must be oriented.
from scpf import Anchor, AnchorFrame
mount = AnchorFrame(
origin=(0, 0, -12),
z=(0, 1, 0),
x=(0, 0, -1),
)
bracket = CornerBracket().attach(
side_board,
parent=Anchor.FRONT_TOP_LEFT,
child=mount,
)There are two ownership patterns. If the datum is an intrinsic part of a reusable component, expose it with anchors() and refer to it by name. If the frame exists only because of a particular assembly or mounting choice, construct the AnchorFrame in that assembly and pass it directly to attach(). This keeps application knowledge out of the generic component definition.
@component
class Sensor:
def anchors(self):
return {
"connector": AnchorFrame(
origin=(12, 0, 4),
z=(1, 0, 0),
x=(0, 0, 1),
)
}
def build(self):
return Box(24, 12, 8)
sensor = Sensor().attach(panel, child="connector")For an unrotated occurrence, Forge lowers an AnchorFrame directly into the native joint.create reference as point, z and x; it does not create a persistent visible joint.origin. Named frames on explicitly rotated occurrences currently use the native origin fallback so SolidCraft owns the transform. A direct AnchorFrame on an explicitly rotated occurrence is not supported yet.
AnchorTopology: follow an edge or corner
AnchorTopology is a named component datum that stays attached to native SolidCraft topology. edge picks an edge, on selects its adjacent planar face and corner optionally chooses one endpoint. The coordinates are selection picks; SolidCraft keeps the selected edge, face and endpoint by topology name as the design changes.
from scpf import AnchorTopology, Box, component
@component
class Board:
def anchors(self):
return {
"mount": AnchorTopology(
edge=(-20, 50, 5),
on=(-20, 50, 10),
corner=(-20, 0, 5),
z=(0, 1, 0),
x=(0, 0, 1),
)
}
def build(self):
return Box(40, 100, 20)This is useful for references such as the straight tangent edge beside a fillet: if dimensions move that edge, the joint can follow it without freezing the original XYZ point. The current implementation supports named or direct AnchorTopology values on non-rotated occurrences. A direct topology anchor is useful when the datum belongs only to one assembly rather than to the reusable component. SCPF deliberately does not transform topology picks itself.
SolidCraft joints remain an internal implementation detail; Forge does not expose a separate public Joint object.
What to test in an assembly
Check the native command list for one component.create per shared definition, expected occurrence.copy counts, and native translate, axis and angle parameters for rotated occurrences. Separately verify native SolidCraft geometry and its bounding dimensions before trusting an assembly image.