Playground
See kSTEP in action.
Curated examples of the kSTEP DSL — product structure and real OCCT geometry, expressed as type-safe Kotlin code. Source on the left, rendered preview on the right.
Pure AP242 product structure — no geometry at all. products, product definitions and a NEXT_ASSEMBLY_USAGE_OCCURRENCE relate a housing to a bracket. Renders as a text-summary card, not a picture — this is what a geometry-free script looks like.
product-structure.kstep.kts
// product-structure.kstep.kts -- a two-part assembly (housing + mounting bracket) with no
// geometry at all: pure AP242 product structure (applicationContext/productContext/
// productDefinitionContext/product/productDefinition/productDefinitionFormation/
// nextAssemblyUsageOccurrence), the layer kSTEP started with before the OCCT geometry track
// existed. `kstep render` falls back to a text-summary card for a script like this one --
// there is nothing to shade, so the preview lists the model's Part 21 instances instead. That
// is expected, correct output, not a rendering failure -- see occt-box.kstep.kts and
// extrude-fillet.kstep.kts for the geometry-bearing examples in this same playground.
//
// Run: kstep render product-structure.kstep.kts -f svg -o product-structure.svg
val appCtx = applicationContext { application = "configuration control" }.getOrThrow()
val prodCtx =
productContext {
name = "engineering"
frameOfReference = appCtx
disciplineType = "mechanical"
}.getOrThrow()
val defCtx =
productDefinitionContext {
name = "engineering"
frameOfReference = appCtx
lifeCycleStage = "design"
}.getOrThrow()
val housing =
product("HSG-100") {
name = "Housing"
description = "Enclosure housing"
frameOfReference = setOf(prodCtx)
}.getOrThrow()
val housingFormation = productDefinitionFormation("HSG-100-F") { ofProduct = housing }.getOrThrow()
val housingDefinition =
productDefinition("HSG-100-D") {
formation = housingFormation
frameOfReference = defCtx
}.getOrThrow()
val bracket =
product("BRK-100") {
name = "Mounting Bracket"
description = "L-shaped mounting bracket"
frameOfReference = setOf(prodCtx)
}.getOrThrow()
val bracketFormation = productDefinitionFormation("BRK-100-F") { ofProduct = bracket }.getOrThrow()
val bracketDefinition =
productDefinition("BRK-100-D") {
formation = bracketFormation
frameOfReference = defCtx
}.getOrThrow()
stepFile(fileName = "hello-assembly.step") {
root(
nextAssemblyUsageOccurrence("NAUO-100") {
name = "housing to bracket"
relatingProductDefinition = housingDefinition
relatedProductDefinition = bracketDefinition
referenceDesignator = "RD-1"
},
)
}occt-box.kstep.kts
// occt-box.kstep.kts -- the simplest possible geometry example: a single OcctKernel.makeBox()
// call bound to a product definition via shape(...). Renders as a real shaded B-Rep solid (six
// flat-shaded quad faces), not a text card -- see product-structure.kstep.kts for what a
// geometry-free script renders as instead.
//
// Run: kstep render occt-box.kstep.kts -f svg -o occt-box.svg
val appCtx = applicationContext { application = "configuration control" }.getOrThrow()
val prodCtx =
productContext {
name = "engineering"
frameOfReference = appCtx
disciplineType = "mechanical"
}.getOrThrow()
val defCtx =
productDefinitionContext {
name = "engineering"
frameOfReference = appCtx
lifeCycleStage = "design"
}.getOrThrow()
val block =
product("BLK-001") {
name = "Block"
description = "40x25x15mm reference block"
frameOfReference = setOf(prodCtx)
}.getOrThrow()
val blockFormation = productDefinitionFormation("BLK-001-F") { ofProduct = block }.getOrThrow()
val blockDefinition =
productDefinition("BLK-001-D") {
formation = blockFormation
frameOfReference = defCtx
}.getOrThrow()
val box = OcctKernel.makeBox(40.0, 25.0, 15.0)
stepFile(fileName = "erste-box.step") {
root(blockDefinition)
shape(blockDefinition, box)
}extrude-fillet.kstep.kts
// extrude-fillet.kstep.kts -- a parametric feature chain: a 2D rectangular profile extruded
// into a prism, then one edge rounded via OcctKernel.fillet(). Renders as real shaded geometry
// -- more triangulated facets than occt-box.kstep.kts because the rounded edge is approximated
// by several small polygons instead of one flat face.
//
// Run: kstep render extrude-fillet.kstep.kts -f svg -o extrude-fillet.svg
val appCtx = applicationContext { application = "configuration control" }.getOrThrow()
val prodCtx =
productContext {
name = "engineering"
frameOfReference = appCtx
disciplineType = "mechanical"
}.getOrThrow()
val defCtx =
productDefinitionContext {
name = "engineering"
frameOfReference = appCtx
lifeCycleStage = "design"
}.getOrThrow()
val part =
product("BRACKET-001") {
name = "Filleted Bracket"
frameOfReference = setOf(prodCtx)
}.getOrThrow()
val prodFormation = productDefinitionFormation("BRACKET-001-F") { ofProduct = part }.getOrThrow()
val definition =
productDefinition("BRACKET-001-D") {
formation = prodFormation
frameOfReference = defCtx
}.getOrThrow()
val profile =
listOf(
ProfilePoint(0.0, 0.0),
ProfilePoint(20.0, 0.0),
ProfilePoint(20.0, 30.0),
ProfilePoint(0.0, 30.0),
)
val prism = OcctKernel.extrudeProfile(profile, 40.0)
val rounded = OcctKernel.fillet(prism, edgeIndex = 0, radius = 5.0)
stepFile(fileName = "extrude-fillet.step") {
root(definition)
shape(definition, rounded)
}enclosure-with-lid.kstep.kts
// enclosure-with-lid.kstep.kts -- a small electronics enclosure: an open housing with rounded
// vertical edges and a 2 mm wall, plus a lid with a locating lip. The lid is placed above the
// housing in an assembly (exploded by LIFT mm; set LIFT = 0.0 to close it). Requires OCCT.
//
// Run: kstep render enclosure-with-lid.kstep.kts -f svg -o enclosure-with-lid.svg
val LIFT = 10.0 // gap between housing rim and lid in the exploded view
val appCtx = applicationContext { application = "configuration control" }.getOrThrow()
val prodCtx = productContext { name = "engineering"; frameOfReference = appCtx; disciplineType = "mechanical" }.getOrThrow()
val defCtx = productDefinitionContext { name = "engineering"; frameOfReference = appCtx; lifeCycleStage = "design" }.getOrThrow()
fun part(id: String, name: String): ProductDefinition {
val p = product(id) { this.name = name; frameOfReference = setOf(prodCtx) }.getOrThrow()
val f = productDefinitionFormation("$id-F") { ofProduct = p }.getOrThrow()
return productDefinition("$id-D") { formation = f; frameOfReference = defCtx }.getOrThrow()
}
val assembly = part("ENC-100", "Enclosure")
val housing = part("ENC-110", "Housing")
val lid = part("ENC-120", "Lid")
// Housing: 60 x 40 x 30 block, the four vertical edges rounded (r = 4), then hollowed with the
// top face removed and a 2 mm wall grown inwards. The inner corners follow with r = 4 - 2 = 2.
val block = OcctKernel.fillet(OcctKernel.makeBox(60.0, 40.0, 30.0), Edges.parallelTo(Direction3.Z), 4.0, expected = 4)
val housingBody = shell(block, Faces.atMax(Direction3.Z), 2.0)
// Lid: 3 mm plate with the same outline, plus a 2 mm lip (55 x 35, r = 1.5) underneath that sits
// inside the 56 x 36 opening with 0.5 mm clearance on each side.
val plate = OcctKernel.fillet(OcctKernel.makeBox(60.0, 40.0, 3.0), Edges.parallelTo(Direction3.Z), 4.0, expected = 4)
val lipBlank = OcctKernel.translate(OcctKernel.makeBox(55.0, 35.0, 2.0), 2.5, 2.5, -2.0)
val lip = OcctKernel.fillet(lipBlank, Edges.parallelTo(Direction3.Z), 1.5, expected = 4)
val lidBody = OcctKernel.union(plate, lip)
val nauoHousing = nextAssemblyUsageOccurrence("NAUO-110") {
name = "housing"; relatingProductDefinition = assembly; relatedProductDefinition = housing; referenceDesignator = "H1"
}.getOrThrow()
val nauoLid = nextAssemblyUsageOccurrence("NAUO-120") {
name = "lid"; relatingProductDefinition = assembly; relatedProductDefinition = lid; referenceDesignator = "L1"
}.getOrThrow()
stepFile(fileName = "enclosure-with-lid.step") {
roots(nauoHousing, nauoLid)
shape(housing, housingBody, colour = StepColour.hex("#5B6770"), layer = "Housing")
shape(lid, lidBody, colour = StepColours.ORANGE, layer = "Lid")
// The housing stays at the origin; the lid rests on the rim at z = 30 (plus the exploded gap).
place(nauoLid, translation = vec(0.0, 0.0, 30.0 + LIFT))
}mounting-plate.kstep.kts
// mounting-plate.kstep.kts -- a mounting plate with four M6 clearance holes and a central 20 mm
// bore, built as a feature history so every edge is addressed by what created it, not by index.
// Change WIDTH (e.g. 80.0 -> 120.0): the outline, the hole positions and all rounded/chamfered
// edges follow. Requires OCCT and PlaneGCS.
//
// Run: kstep render mounting-plate.kstep.kts -f svg -o mounting-plate.svg
import dev.kstep.geometry.feature.FeatureRebuilder
import dev.kstep.geometry.feature.FeatureSequence
import dev.kstep.geometry.feature.GeneratedEdges
import dev.kstep.geometry.feature.HoleFeature
import dev.kstep.geometry.feature.SelectEdges
import dev.kstep.geometry.feature.SelectedChamferFeature
import dev.kstep.geometry.feature.SelectedFilletFeature
import dev.kstep.sketch.SketchSources
val WIDTH = 80.0 // plate width in x -- the one number to change
val DEPTH = 50.0
val THICKNESS = 8.0
val INSET = 10.0 // hole centre distance from the plate edges
val appCtx = applicationContext { application = "configuration control" }.getOrThrow()
val prodCtx = productContext { name = "engineering"; frameOfReference = appCtx; disciplineType = "mechanical" }.getOrThrow()
val defCtx = productDefinitionContext { name = "engineering"; frameOfReference = appCtx; lifeCycleStage = "design" }.getOrThrow()
val plate = product("MP-200") { name = "Mounting plate"; frameOfReference = setOf(prodCtx) }.getOrThrow()
val plateFormation = productDefinitionFormation("MP-200-F") { ofProduct = plate }.getOrThrow()
val definition = productDefinition("MP-200-D") { formation = plateFormation; frameOfReference = defCtx }.getOrThrow()
val top = THICKNESS + 1.0 // drills start 1 mm above the plate and go down
val features =
FeatureSequence(
listOf(
// 0: sketched outline, extruded; the corners are the sketch points p0..p3
sketchFeature(mapOf("width" to WIDTH), SketchOperation.Extrude(THICKNESS), label = "outline") { p ->
rectangle(0.0, 0.0, p["width"], DEPTH)
},
// 1: round the four corners by name (generated by feature 0 from p0..p3)
SelectedFilletFeature(0, GeneratedEdges(0, SketchSources.corners("p0", "p1", "p2", "p3"), expected = 4), 5.0),
// 2..5: four M6 clearance holes (d = 6.6), positioned from WIDTH
HoleFeature(1, 6.6, 10.0, INSET, INSET, top),
HoleFeature(2, 6.6, 10.0, WIDTH - INSET, INSET, top),
HoleFeature(3, 6.6, 10.0, WIDTH - INSET, DEPTH - INSET, top),
HoleFeature(4, 6.6, 10.0, INSET, DEPTH - INSET, top),
// 6: central bore d = 20
HoleFeature(5, 20.0, 10.0, WIDTH / 2, DEPTH / 2, top),
// 7: round the entry rim of the bore by name: the ring where drill 6 entered the plate
SelectedFilletFeature(6, GeneratedEdges(6, listOf(HoleWall), GeneratedRole.RIM_ENTRY, expected = 1), 1.5),
// 8: 0.5 mm chamfer on the four small hole rims on top, chosen by geometry
SelectedChamferFeature(
7,
SelectEdges(Edges.ofType(EdgeKind.CIRCLE, radius = 3.3) and Edges.atMax(Direction3.Z), expected = 4),
0.5,
),
),
)
val body = FeatureRebuilder.rebuild(features).final
stepFile(fileName = "mounting-plate.step") {
root(definition)
shape(definition, body, colour = StepColour.hex("#8A9BA8"), layer = "Plates")
}symmetric-bracket.kstep.kts
// symmetric-bracket.kstep.kts -- a U-shaped fork bracket built from one half: an L-profile is
// extruded, mirrored in the plane x = 0 and fused with the original, so both legs are identical by
// construction. The four outer vertical edges of the legs get a 2 mm chamfer. Requires OCCT.
//
// Run: kstep render symmetric-bracket.kstep.kts -f svg -o symmetric-bracket.svg
val appCtx = applicationContext { application = "configuration control" }.getOrThrow()
val prodCtx = productContext { name = "engineering"; frameOfReference = appCtx; disciplineType = "mechanical" }.getOrThrow()
val defCtx = productDefinitionContext { name = "engineering"; frameOfReference = appCtx; lifeCycleStage = "design" }.getOrThrow()
val bracket = product("FB-300") { name = "Fork bracket"; frameOfReference = setOf(prodCtx) }.getOrThrow()
val bracketFormation = productDefinitionFormation("FB-300-F") { ofProduct = bracket }.getOrThrow()
val definition = productDefinition("FB-300-D") { formation = bracketFormation; frameOfReference = defCtx }.getOrThrow()
// Right half in the XY plane: a 35 mm base (6 mm thick) starting on the mirror plane x = 0, and a
// 6 mm leg rising to y = 25 at its outer end.
val halfProfile =
listOf(
ProfilePoint(0.0, 0.0),
ProfilePoint(35.0, 0.0),
ProfilePoint(35.0, 25.0),
ProfilePoint(29.0, 25.0),
ProfilePoint(29.0, 6.0),
ProfilePoint(0.0, 6.0),
)
val half = OcctKernel.extrudeProfile(halfProfile, 30.0)
// The mirrored copy shares the face x = 0 with the original; union fuses them into one solid.
val fork = OcctKernel.union(half, mirror(half, MirrorPlane.YZ))
// Outer vertical edges: parallel to Z and lying in one of the two outermost planes x = -35 / x = 35.
val outerEdges = Edges.parallelTo(Direction3.Z) and (Edges.atMax(Direction3.X) or Edges.atMin(Direction3.X))
val chamfered = OcctKernel.chamfer(fork, outerEdges, 2.0, expected = 4)
// Stand it upright: turn 90 degrees about X (profile y becomes z), then shift back to y >= 0.
val body = OcctKernel.translate(OcctKernel.transformed(chamfered, Placement.rotationX(90.0)), 0.0, 30.0, 0.0)
stepFile(fileName = "symmetric-bracket.step") {
root(definition)
shape(definition, body, colour = StepColours.BLUE, layer = "Brackets")
}nested-assembly.kstep.kts
// nested-assembly.kstep.kts -- a fixture station: a base plate carrying a stop sub-assembly (an
// angle stop with two locating pins). The sub-assembly is placed on the plate with a translation
// and a 90 degree turn about Z; inside it, the pin part is used twice at two places. Placements
// compose from the root down. Requires OCCT.
//
// Run: kstep render nested-assembly.kstep.kts -f svg -o nested-assembly.svg
val appCtx = applicationContext { application = "configuration control" }.getOrThrow()
val prodCtx = productContext { name = "engineering"; frameOfReference = appCtx; disciplineType = "mechanical" }.getOrThrow()
val defCtx = productDefinitionContext { name = "engineering"; frameOfReference = appCtx; lifeCycleStage = "design" }.getOrThrow()
fun part(id: String, name: String): ProductDefinition {
val p = product(id) { this.name = name; frameOfReference = setOf(prodCtx) }.getOrThrow()
val f = productDefinitionFormation("$id-F") { ofProduct = p }.getOrThrow()
return productDefinition("$id-D") { formation = f; frameOfReference = defCtx }.getOrThrow()
}
fun usage(id: String, parent: ProductDefinition, child: ProductDefinition, designator: String) =
nextAssemblyUsageOccurrence(id) {
name = id; relatingProductDefinition = parent; relatedProductDefinition = child; referenceDesignator = designator
}.getOrThrow()
val station = part("FS-400", "Fixture station") // root, no geometry of its own
val basePlate = part("FS-410", "Base plate")
val stopUnit = part("FS-420", "Stop unit") // sub-assembly, no geometry of its own
val stop = part("FS-421", "Angle stop")
val pin = part("FS-422", "Locating pin")
val uPlate = usage("NAUO-410", station, basePlate, "P1")
val uStop = usage("NAUO-420", station, stopUnit, "S1")
val uAngle = usage("NAUO-421", stopUnit, stop, "A1")
val uPin1 = usage("NAUO-422", stopUnit, pin, "D1")
val uPin2 = usage("NAUO-423", stopUnit, pin, "D2")
// Angle stop: L-profile (30 x 6 and 6 x 24) extruded 20 mm high.
val angle = OcctKernel.extrudeProfile(
listOf(ProfilePoint(0.0, 0.0), ProfilePoint(30.0, 0.0), ProfilePoint(30.0, 6.0),
ProfilePoint(6.0, 6.0), ProfilePoint(6.0, 24.0), ProfilePoint(0.0, 24.0)),
20.0,
)
stepFile(fileName = "nested-assembly.step") {
roots(uPlate, uStop, uAngle, uPin1, uPin2)
shape(basePlate, OcctKernel.makeBox(80.0, 50.0, 6.0), colour = StepColours.GREY, layer = "Base")
shape(stop, angle, colour = StepColours.BLUE, layer = "Stops")
shape(pin, OcctKernel.makeCylinder(3.0, 16.0), colour = StepColours.ORANGE, layer = "Pins")
// Sub-assembly on top of the plate (z = 6), turned 90 degrees: (x, y, z) -> (-y, x, z), then +(50, 10, 6).
place(uStop, translation = vec(50.0, 10.0, 6.0), rotation = Rotation.about(Vec3.Z, 90.0))
// Inside the sub-assembly: the angle stays at its origin, the pins stand in the open corner.
place(uPin1, translation = vec(15.0, 15.0, 0.0))
place(uPin2, translation = vec(22.0, 12.0, 0.0))
}parametric-cover.kstep.kts
// parametric-cover.kstep.kts -- a protective end cap (open at its right end) whose three main dimensions
// are parameters. Every edge and face is chosen by a geometric rule instead of an index, so the
// selection moves with the geometry when a parameter changes (try HEIGHT = 35.0). Requires OCCT.
//
// Run: kstep render parametric-cover.kstep.kts -f svg -o parametric-cover.svg
val WIDTH = 50.0 // x
val HEIGHT = 20.0 // z -- try 35.0
val WALL = 3.0 // wall thickness of the shell
val DEPTH = 30.0 // y, fixed here
val ROUND = 8.0 // radius of the rounded front-left top edge
val appCtx = applicationContext { application = "configuration control" }.getOrThrow()
val prodCtx = productContext { name = "engineering"; frameOfReference = appCtx; disciplineType = "mechanical" }.getOrThrow()
val defCtx = productDefinitionContext { name = "engineering"; frameOfReference = appCtx; lifeCycleStage = "design" }.getOrThrow()
val cover = product("PC-500") { name = "Parametric cover"; frameOfReference = setOf(prodCtx) }.getOrThrow()
val coverFormation = productDefinitionFormation("PC-500-F") { ofProduct = cover }.getOrThrow()
val definition = productDefinition("PC-500-D") { formation = coverFormation; frameOfReference = defCtx }.getOrThrow()
val block = OcctKernel.makeBox(WIDTH, DEPTH, HEIGHT)
// Of the four edges running along Y, the one nearest to a point high above the origin is the top
// edge at x = 0 -- for every HEIGHT below 1000. `within` restricts the candidates first.
val topLeftEdge = Edges.nearest(Point3(0.0, 0.0, 1000.0), within = Edges.parallelTo(Direction3.Y))
val rounded = OcctKernel.fillet(block, topLeftEdge, ROUND, expected = 1)
// Hollow it out: remove the end face (highest in X) and grow a WALL-thick wall inwards. The open
// face is found again when WIDTH changes.
val body = shell(rounded, Faces.atMax(Direction3.X), WALL)
stepFile(fileName = "parametric-cover.step") {
root(definition)
shape(definition, body, colour = StepColour.hex("#2E7D5B"), layer = "Covers")
// The outer top face (highest in Z) goes on its own layer in the STEP file; it stays the top
// face whatever HEIGHT is. (A face colour next to a part colour works as well since v0.3.0;
// this example uses a face layer.)
styleFaces(definition, Faces.atMax(Direction3.Z), layer = "Top", expected = 1)
}