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.

Model objects and parameters

A model is a normal Python class

Numeric class attributes become editable SolidCraft parameters when SCPF compiles a plain model class. build() returns geometry. If a file contains exactly one public class with build(), that class is the root automatically; no trailing constructor call or launcher file is needed.

from scpf import Box

class Plate:
    length = 100.0
    width = 60.0
    thickness = 10.0

    def build(self):
        return Box(self.length, self.width, self.thickness)

Run that source file directly with python -m scpf plate.py --connect. The same rule lets a reusable component file serve as its standalone model while assemblies import the exact same class. If a file contains several public model classes, SCPF deliberately does not guess: finish the script with an explicit call such as Assembly() to choose the root.

An explicit final call is also how you override root parameters for a particular run, for example Plate(width=80). Arithmetic such as self.length / 2 is preserved symbolically for supported expressions; general Python computations are not automatically made parametric.

Parameter intent is visible in the name

SCPF distinguishes three kinds of numeric class attributes. This keeps a Python build setting from looking like a native editable CAD parameter.

class Display:
    PANEL_COUNT = 5          # fixed constant
    _panel_pitch = 160.0     # Forge/build-time input
    opening_width = 844.0    # native model parameter
NameMeaningSolidCraft parameter
UPPER_CASEFixed constantNo
_lower_caseForge/build-time inputNo
lower_caseEditable model parameterYes

If a public lower-case parameter is consumed only as a concrete Python value—for example through pv()—Forge emits a ModelParameterWarning. The same warning is emitted when a parameter remains native in some geometry but is also flattened into concrete occurrence placement. Such a parameter is only partly associative: editing it in SolidCraft would update only part of the model. Keep Placement coordinates symbolic or rename an intentionally build-time input with a leading underscore.

Share one model parameter across child components

Passing a parent parameter into several component inputs keeps one native SolidCraft parameter instead of creating component-specific duplicates.

bottom = BottomBoard(corner_radius=self.corner_radius)
roof = RoofBoard(corner_radius=self.corner_radius)
bracket = Bracket(
    bracket_width=self.bracket_width,
    inside_corner_radius=self.corner_radius,
)

Here the wooden fillets and bracket inside fillet all depend on the same corner_radius. Passing the parent parameter into the child input reuses that existing native dependency rather than creating a duplicate child parameter.

Reusable component defaults stay fixed unless they are explicitly published with include=. Parent Parameters/Expressions passed into child inputs always stay symbolic and reuse the existing parent dependency.

Bracket = component(
    CornerBracket,
    include=("inside_corner_radius",),
)

# Or publish all public defaults explicitly:
FullyEditableBracket = component(CornerBracket, include="*")

This publication rule is recorded in change 0003.

Shape versus component occurrence

Shape describes geometry or a feature expression (Box, Hole, an extrusion). A component occurrence is one placed instance of a shared, editable model definition. Do not confuse a new occurrence with a new feature history.

from scpf import Box, Placement, component

class Block:
    def build(self):
        return Box(40, 20, 10)

BlockComponent = component(Block)
first = BlockComponent(placement=Placement(x=-25))
second = first.copy(placement=Placement(x=25))
assembly = first + second

The two occurrences share the same Block definition. Placement is occurrence creation metadata: XYZ is absolute in the parent coordinate frame and optional rotation adds orientation. The component definition never receives placement as a model parameter.

Groups are actual native parent components

blocks = (first + second).group("Blocks")

Grouping changes the browser hierarchy, not the geometry’s orientation. At present one shared definition cannot be split among different groups.

Important boundaries

Associative attachment is supported for a limited set of rectangular component faces. General mates, arbitrary face queries and rotational constraints are not implemented as a complete assembly solver.

Next:Positioning and orientation explains how to place geometry and component occurrences, and when at(), on() or attach() is the right choice.

Symbolic CAD math

Use cadmath when an editable model relationship needs native math beyond ordinary arithmetic. The namespace avoids replacing Python built-ins such as min, max, abs and round.

mid_g = cadmath.min(self.mid_round, self.mid_wall / 2 - 0.05)
mid_tip = cadmath.sqrt(
    (self.mid_outer_r - mid_g) ** 2
    - (self.mid_outer_r - self.mid_wall + mid_g) ** 2
)
lane = cadmath.round(self.mid_z / 2 / self.grid) * self.grid

Supported functions are cadmath.min, cadmath.max, cadmath.sqrt, cadmath.abs, cadmath.round, cadmath.floor and cadmath.atan. The result remains a native symbolic dependency whenever any input is a Parameter or Expression. cadmath.atan returns degrees, matching SolidCraft CAD expressions.