Skip to content
Stable.scad@modelscript/scad 8 diagnostic rules
Parser WASM GLR
Diagnostics 8 rules
DAE Arena AST Only
Simulation Co-sim / Export
Projections CSG, STEP
Live ExampleFlangedBearingHousing.scad

Parametric Flanged Bearing Pillow-Block CSG Solid

Programmatic OpenSCAD constructive solid geometry combining a mounting base plate, cylindrical boss, center bore, and bolt pattern.

Playground
Source (26 lines)
1// Parametric Flanged Bearing Housing
2$fn = 64;
3base_w = 80;
4base_d = 50;
5base_h = 10;
6boss_r = 22;
7boss_h = 32;
8bore_r = 12;
9 
10difference() {
11  union() {
12    // Base mounting flange
13    translate([0, 0, base_h / 2])
14      cube([base_w, base_d, base_h], center = true);
15    // Cylindrical bearing boss
16    cylinder(h = boss_h, r = boss_r, center = false);
17  }
18  // Precision shaft through-bore
19  translate([0, 0, -1])
20    cylinder(h = boss_h + 2, r = bore_r, center = false);
21  // Four M8 mounting bolt holes
22  for (sx = [-28, 28], sy = [-16, 16]) {
23    translate([sx, sy, -1])
24      cylinder(h = base_h + 2, r = 4.2, center = false);
25  }
26}
3D Isometric CSG Mesh & Boolean Tree
3D CONSTRUCTIVE SOLID GEOMETRY r_boss = 22 mm r_bore = 12 mm 80 × 50 × 10 mm CSG BOOLEAN EVALUATION DAG difference() (−) union() (∪) − Cut Cylinders shaft bore (r=12) 4× M8 bolts (r=4.2) cube([80,50,10]) Base Flange cylinder(32, 22) Bearing Boss
Drag to pan · Click % to reset

OpenSCAD (.scad) ​

@modelscript/scad (languages/scad) parses parametric OpenSCAD scripts and evaluates Constructive Solid Geometry (CSG) trees via @modelscript/cad into exact OpenCascade B-Rep solids, watertight triangle meshes, STEP AP214/AP242 exports, and Modelica MultiBody parameters.


Supported Syntax & Fluent Method Chaining ​

In addition to standard OpenSCAD primitives (cube, sphere, cylinder, polyhedron, circle, square, polygon), boolean operations (union, difference, intersection, hull, minkowski), extrusions (linear_extrude, rotate_extrude), and control flow (module, function, for, if/else), @modelscript/scad supports fluent method chaining (ChainedSolid in languages/scad/src/evaluator.ts) and boundary port tagging:

c
wall_thickness = 4.0;
mount_radius = 12.0;

// Fluent method chaining with .fillet(), .chamfer(), .translate(), .rotate()
bracket = cube([60, 40, wall_thickness], center=true)
  .fillet(1.5)
  .translate([0, 0, wall_thickness / 2]);

// Explicit physical port tagging for SysML v2 / Modelica MultiBody & CFD/FEA binding
tag_port("base_mount", "frame", [0, 0, -1])
  difference() {
    bracket;
    cylinder(h=10, r=mount_radius, center=true).chamfer(0.5);
  }

Supported Chained Methods (ChainedSolid) ​

MethodSignatureDescription
.translate(v)translate([dx, dy, dz])Translates the solid by vector [dx, dy, dz]
.rotate(a, v?)rotate([rx, ry, rz]) or rotate(deg, axis)Rotates the solid by Euler angles or axis-angle
.scale(v)scale([sx, sy, sz])Scales the solid non-uniformly or uniformly
.mirror(v)mirror([nx, ny, nz])Mirrors the solid across the plane with normal v
.color(c, alpha?)color("steelblue", 0.9)Assigns RGBA display metadata
.fillet(r)fillet(radius)Applies a 3D edge fillet of radius r>0
.chamfer(d)chamfer(distance)Applies a 3D edge chamfer of distance d>0

Semantic Linter & Diagnostic Codes ​

lintScadCst(sourceText) (languages/scad/src/linter.ts) performs static scope resolution, constant folding, and geometric validity checking across 9 diagnostic rules:

8 rules7 error1 warning Run with msx lint

CodeRuleSeverityMessage
K1001SCAD_UNDEFINED_VARIABLEerrorUndefined variable '<name>'.
K1002SCAD_UNDEFINED_FUNCTIONerrorUndefined function '<name>'.
K1003SCAD_UNDEFINED_MODULEerrorUndefined module '<name>'.
K1004SCAD_DIVISION_BY_ZEROerrorDivision by zero in expression.
K1005SCAD_INVALID_DIMENSIONerrorInvalid non-positive dimension (<val>) in '<param>': dimensions must be > 0.
K1006SCAD_ARGUMENT_COUNTerrorToo many arguments to '<name>': expected at most <expected>, got <actual>.
K1007SCAD_UNKNOWN_PARAMETERerrorUnknown parameter '<param>' in call to '<callable>'.
K1008SCAD_DUPLICATE_DECLARATIONwarningVariable '<name>' is assigned multiple times in the same scope.

Generated from languages/scad/src/errors.ts. All languages →


3D Viewport Gizmo Writeback (ScadPatcher) & STEP Export ​

  • Surgical AST Writeback (ScadPatcher in languages/scad/src/patcher.ts): When a user drags a 3D translation/rotation/scale gizmo in the CAD viewport, ScadPatcher (patchNode, patchVariable, patchTransformArgument, patchVectorComponent, wrapPrimitiveWithTransform, patchOrInsertTransform) updates the exact CST byte spans in the .scad source without reformatting surrounding code or comments.
  • STEP AP214/AP242 Export (compileScadToStep): Evaluates the .scad CSG tree and serializes exact B-Rep analytical surfaces (PLANE, CYLINDRICAL_SURFACE, SPHERICAL_SURFACE, MANIFOLD_SOLID_BREP) to ISO 10303-21 .step.
bash
# Project a parametric OpenSCAD file to an ISO 10303-21 STEP CAD file
npx msx polyglot project bracket.scad --target step --out bracket.step

# Or extract Embedded CSG from a Modelica model to OpenSCAD
npx msx csg SatelliteChassis satellite.mo > bracket.scad

Polyglot TGG Rules ​

@modelscript/scad registers 13 bidirectional Triple Graph Grammar (TGG) rules in languages/scad/src/language.ts:

Rule NameSource (scad)Target LanguageTarget Construct
ScadModuleToSysmlPartModuleDeclarationsysml2PartDef
ScadProjectedAreaToModelicaParamScadScript (projectedArea, volume)modelicaComponentClause (parameter Real)
ScadProjectedAreaToSysmlAttributeScadScript (projectedArea, volume)sysml2AttributeUsage
ScadTagPortToSysmlPortModuleInstantiation (tag_port)sysml2PortUsage
ScadVariableToSysmlAttributeVariableAssignmentsysml2AttributeUsage
ScadSolidToStepProductModuleInstantiation (cube)stepDataEntity (PRODUCT)
ScadCylinderToStepProductModuleInstantiation (cylinder)stepDataEntity (CYLINDRICAL_SURFACE)
ScadSphereToStepProductModuleInstantiation (sphere)stepDataEntity (SPHERICAL_SURFACE)
ScadBooleanOpToStepCompositeModuleInstantiation (union / difference / intersection)stepDataEntity (BOOLEAN_RESULT)
ScadTagPortToModelicaFrameModuleInstantiation (tag_port)modelicaComponentClause (Modelica.Mechanics.MultiBody.Interfaces.Frame_a)
ScadCubeToMultiBodyShapeModuleInstantiation (cube)modelicaComponentClause (Modelica.Mechanics.MultiBody.Visualizers.FixedShape "box")
ScadCylinderToMultiBodyShapeModuleInstantiation (cylinder)modelicaComponentClause (Modelica.Mechanics.MultiBody.Visualizers.FixedShape "cylinder")
ScadSphereToMultiBodyShapeModuleInstantiation (sphere)modelicaComponentClause (Modelica.Mechanics.MultiBody.Visualizers.FixedShape "sphere")

Open-Core under the GNU AGPL v3 License; Enterprise Edition (ee/) under the ModelScript Enterprise License. • Trademark Policy