Parametric & Surface Modeling

Rhino, SolidWorks, Fusion 360, CATIA, AutoCAD 3D - all driven by the same sketch-to-solid pipeline and assembly constraint system.

Sketch-Based Features

Sketch, Extrude, Fillet
NEW CAD SKETCH ON PLANE "XY" SET ?sketch
AFTER CAD ?sketch RECTANGLE FROM 0,0 TO 80,40 SET ?outline
AFTER CAD EXTRUDE ?sketch HEIGHT 10 SET ?bracket

AFTER CAD ?bracket EDGE AT 80,0,5 SET ?e1
AFTER CAD ?bracket EDGE AT 80,40,5 SET ?e2
AFTER CAD FILLET EDGES [?e1 AND ?e2] RADIUS 4 ON ?bracket SET ?bracket
Revolve
NEW CAD SKETCH ON PLANE "XZ" SET ?profile
AFTER CAD ?profile ARC CENTER 0,0 RADIUS 20 START 0 END 180 SET ?arc
AFTER CAD REVOLVE ?profile AXIS ?arc ANGLE 360 SET ?sphere
A Primitive Solid
NEW CAD BOX SIZE 20,10,5 SET ?block
AFTER EMIT ?block("volume")
(* 1000 - a solid exists immediately, without a sketch *)

A box is the one solid that requires no profile. Every other form begins with a sketch, which carries its geometry until a feature consumes it: extruding a circular sketch produces a cylinder, extruding a rectangular one produces a block. The sketch itself is not a solid, and its volume is only defined once a feature has been applied.

Sketch to Solid
NEW CAD SKETCH ON PLANE "XY" SET ?sk
AFTER CAD ?sk CIRCLE CENTER 0,0 RADIUS 10 SET ?profile
AFTER CAD EXTRUDE ?profile HEIGHT 20 SET ?cylinder
AFTER EMIT ?cylinder("volume")
(* 6283.19 - pi x 10^2 x 20 *)
Sweep and Loft
NEW CAD SKETCH ON PLANE "XY" SET ?bar
AFTER CAD ?bar RECTANGLE FROM -5,-2 TO 5,2
AFTER SET ?path AS ["0,0,0" AND "0,0,80"]
AFTER CAD SWEEP ?bar PATH ?path TWIST 180 SET ?twisted
AFTER EMIT ?twisted("volume")
(* 3200 - a 10 x 4 bar 80 long, turned half a revolution along its length *)
Sweep and Loft (a second example)
NEW CAD SKETCH ON PLANE "XY" SET ?s1
AFTER CAD ?s1 CIRCLE CENTER 0,0 RADIUS 20
AFTER NEW CAD SKETCH ON PLANE "XY" OFFSET 40 SET ?s2
AFTER CAD ?s2 RECTANGLE FROM -10,-10 TO 10,10
AFTER CAD LOFT PROFILES [?s1 AND ?s2] SET ?blended
AFTER EMIT ?blended("volume")
Shell, Pattern, Mirror, Boolean
NEW CAD BOX SIZE 80,40,20 SET ?bracket
AFTER CAD ?bracket FACE AT 40,20,20 SET ?topFace
AFTER CAD SHELL ?bracket THICKNESS 1 REMOVE FACES [?topFace] SET ?bracket
AFTER NEW CAD SKETCH ON PLANE "XY" SET ?sk
AFTER CAD ?sk CIRCLE CENTER 10,20 RADIUS 3 SET ?hole
AFTER CAD EXTRUDE ?hole HEIGHT 30 SET ?holeSolid
AFTER CAD PATTERN LINEAR ?holeSolid DIRECTION 1,0,0 COUNT 4 SPACING 20 SET ?pegs
AFTER CAD MIRROR ?bracket PLANE "YZ" SET ?mirrored
AFTER CAD BOOLEAN UNION ?bracket WITH ?mirrored SET ?final

A sketch keeps what is drawn in it: RECTANGLE FROM x,y TO x,y (opposite corners), CIRCLE CENTER x,y RADIUS r and ARC CENTER x,y RADIUS r START a END b (degrees). Written without SET, a shape still lands in the sketch, so CAD EXTRUDE ?sketch extrudes what was drawn. ON PLANE is "XY", "XZ" or "YZ", and OFFSET lifts the plane along its normal - which is how the two profiles of a loft come to be apart. EXTRUDE grows along the plane's normal; REVOLVE ... AXIS turns about "x", "y", "z", a direction, or an arc - whose axis is its chord, so a half circle becomes a sphere. SWEEP ... PATH takes the path as a list of points, "x,y,z"; TWIST turns the profile through that angle along its length. MIRROR ... PLANE is "YZ", "XZ", "XY" or a face picked with FACE AT.

Freeform Surfacing

NURBS Surface from Curves
SET ?c1 AS ["0,0,0" AND "10,0,2" AND "20,0,0"]
AFTER SET ?c2 AS ["0,10,1" AND "10,10,4" AND "20,10,1"]
AFTER SET ?c3 AS ["0,20,0" AND "10,20,2" AND "20,20,0"]
AFTER NEW CAD SURFACE FROM CURVES [?c1 AND ?c2 AND ?c3] SET ?surf
AFTER CAD SURFACE ?surf POLES SET ?pt
AFTER CAD SURFACE ?surf CONTROL POINT ?pt(4) MOVE TO 10,10,8
AFTER CAD SURFACE ?surf DEGREE U 5 V 5
AFTER CAD THICKEN ?surf THICKNESS 1 SET ?panel
AFTER EMIT ?panel("volume")

A curve is a list of points - "x,y,z" - or anything with edges: a sketch, a sweep's path, another surface's edge. The surface is a B-spline through them, in order. CAD SURFACE ?surf POLES lists its control points, each {u, v, at, weight}, and CONTROL POINT takes one of those, a [u, v] pair counting from 0, or one number counting row by row; MOVE TO puts it somewhere else and the surface follows. DEGREE U n V m raises the surface's degree - smoother, with more control points; a degree is raised, never lowered. CAD SOLID FROM SURFACES [...] sews surfaces into a solid and refuses, with that reason, when there is a gap between them.

Assemblies, Mates & Multibody Dynamics

Static mates are constraints. Real motion needs mass, inertia, and a dynamics solver - the same distinction as SolidWorks Motion versus a plain assembly.

Assembly with Mates
NEW CAD BOX SIZE 40,40,10 SET ?bracket
AFTER NEW CAD BOX SIZE 20,20,20 SET ?housing
AFTER NEW CAD ASSEMBLY SET ?asm
AFTER CAD ?asm INSERT COMPONENT ?bracket AS "bracket" SET ?c1
AFTER CAD ?asm INSERT COMPONENT ?housing AS "housing" SET ?c2
AFTER CAD ?c1 FACE AT 20,20,0 SET ?f1
AFTER CAD ?c2 FACE AT 10,10,20 SET ?f2
AFTER CAD ?asm MATE ?c1 FACE ?f1 COINCIDENT WITH ?c2 FACE ?f2
AFTER CAD ?asm INTERFERENCE CHECK SET ?clashes
Rigid-Body Dynamics - Two-Link Arm
NEW CAD BOX SIZE 40,40,20 SET ?base
AFTER NEW CAD BOX SIZE 200,20,10 SET ?link1
AFTER NEW CAD BOX SIZE 150,20,10 SET ?link2
AFTER NEW CAD ASSEMBLY SET ?asm
AFTER CAD ?asm INSERT COMPONENT ?base AS "base" SET ?baseComp
AFTER CAD ?asm INSERT COMPONENT ?link1 AS "link1" SET ?link1Comp
AFTER CAD ?asm INSERT COMPONENT ?link2 AS "link2" SET ?link2Comp
AFTER CAD ?link1Comp MASS 5 INERTIA 0.1,0.1,0.2
AFTER CAD ?link2Comp MASS 3 INERTIA 0.05,0.05,0.1
AFTER CAD ?asm JOINT REVOLUTE BETWEEN ?baseComp AND ?link1Comp AXIS "z" AT 10,10,20 SET ?joint1
AFTER CAD ?asm JOINT REVOLUTE BETWEEN ?link1Comp AND ?link2Comp AXIS "z" AT 190,10,10 SET ?joint2
AFTER CAD ?asm TORQUE ?joint1 AMOUNT 2 WAVEFORM "sine" FREQUENCY 0.5
AFTER CAD ?asm MOTION SIMULATE DURATION 5 STEP 0.01 SET PROMISE ?motion
AFTER WAIT FOR ?motion SET ?trajectory
AFTER CAD ?trajectory EXTRACT POSITION OF ?link2Comp SET ?path
AFTER EMIT ?path("final")
Statement Meaning
CAD ?comp MASS m [INERTIA ixx,iyy,izz]Mass in kg; inertia about the centre of mass in kg·m². Without MASS a part weighs what steel of its volume would; without INERTIA it is worked out from the part's shape
CAD ?asm JOINT REVOLUTE BETWEEN ?a AND ?b AXIS "z" [AT x,y,z]A hinge: ?b turns relative to ?a about the axis ("x", "y", "z" or a direction). It sits AT the point given, in mm, or else where the two parts meet. A component that hangs from no joint is fixed to the ground
CAD ?asm TORQUE ?joint AMOUNT n WAVEFORM w FREQUENCY fDrives the joint: n in N·m, waveform "constant", "sine", "cosine", "square", "triangle" or "sawtooth" at f Hz
CAD ?asm MOTION SIMULATE DURATION s STEP dtIntegrates the whole coupled mechanism (fourth-order Runge-Kutta) under gravity, 9.81 m/s² down. Answers a trajectory: times, each joint's angles in degrees, each component's centre of mass over time in mm, and final_angles
CAD ?trajectory EXTRACT POSITION OF ?compThat component's path: times, points (x,y,z in mm) and final

Masses, joints and drives are written without SET and are kept on the variable they are said of - the component, or the assembly.

Rigid-Body Motion

A link is a body in a chain: a mass on an arm, hinged at one end. NEW CAD LINK describes one and returns it as a value - nothing is created and no document is touched. An array of them is a linkage, and CAD SIMULATE MOTION integrates it forward under gravity.

Every quantity is in the same units the rest of CAD uses: millimetres, kilograms, degrees, and gravity in mm/s². Earth is -9810, which is the default and the reason it is negative - down.

On NEW CAD LINK Meaning Default
MASSMass of the body, kg1
LENGTHDistance from its hinge to its mass, mm100
ANGLEStarting angle, degrees. 0 is horizontal - where gravity pulls hardest. ±90 is vertical0
VELOCITYStarting angular velocity, deg/s0
TORQUEConstant torque applied at the hinge, Nmm0
DAMPINGResistance at the hinge. Zero swings forever0
INERTIAMoment of inertia. Zero derives it from mass and length0
A Pendulum, Released Horizontally
NEW CAD LINK MASS 1 LENGTH 1000 ANGLE 0 SET ?arm
AFTER NEW ARRAY SET ?links
AFTER APPEND ?arm TO ?links
AFTER CAD SIMULATE MOTION ?links DURATION 4 STEP 0.001 SET ?run
AFTER EMIT ?run

Angles are measured from horizontal. At 0 the arm is level and gravity has the most leverage on it; at -90 it hangs straight down; at 90 it stands straight up. The torque follows cos of the angle, which is why a link starting at exactly 90 does not move - it is balanced, and the solver is right to leave it there. Nudge it with ANGLE 89 and it falls.

Released from horizontal, an undamped pendulum swings down through the bottom and up the far side to -180, where its mass is level with the pivot again, then returns to 0. It should never pass either end. That is the check worth running first: angles beyond the pair mean the step is too coarse and the integrator is adding energy rather than conserving it. Halve STEP until it settles.

A Double Pendulum
NEW CAD LINK MASS 1 LENGTH 500 ANGLE 0 SET ?upper
AFTER NEW CAD LINK MASS 0.5 LENGTH 400 ANGLE 0 SET ?lower
AFTER NEW ARRAY SET ?chain
AFTER APPEND ?upper TO ?chain
AFTER APPEND ?lower TO ?chain
AFTER CAD SIMULATE MOTION ?chain DURATION 6 STEP 0.0005 SET ?run
AFTER EMIT ?run

Order matters: the first link hinges on the world, and each one after hinges on the end of the one before it.

Each link is integrated independently and its angle is relative to the one before it, so a chain is a sequence of driven arms rather than a fully coupled multibody solve. For a linkage under load that is what you want; for a chaotic double pendulum, expect the shape of the motion rather than a trajectory that matches a reference to many decimal places.

A driven joint is torque, not motion. There is no way to say “rotate at this speed”, because a rigid-body solver answers what the physics does rather than what you wanted. Apply TORQUE and add DAMPING, and the steady speed falls out of the two.
Gravity in millimetres. -9810 rather than -9.81, because every length in CAD is a millimetre. Passing -9.81 gives a world where everything falls a thousand times too slowly, and nothing in the output says so.

CAD THICKEN

Gives a surface thickness, turning it into a solid. A lofted or swept surface has area but no volume - it cannot be printed, meshed for analysis, or subtracted from anything. THICKNESS is in millimetres and the material is added to one side.

A Surface Made Printable
SET ?c1 AS ["0,0,0" AND "40,0,10" AND "80,0,0"]
AFTER SET ?c2 AS ["0,40,0" AND "40,40,20" AND "80,40,0"]
AFTER NEW CAD SURFACE FROM CURVES [?c1 AND ?c2] SET ?skin
AFTER CAD THICKEN ?skin THICKNESS 2 SET ?shell
AFTER CAD EXPORT ?shell AS "stl" INTO "/root/cad/shell.stl"

Check it worked by measuring: a surface reports a volume of zero, a thickened one does not.

Proving It Is Solid
CAD MEASURE ?skin SET ?before
AFTER CAD MEASURE ?shell SET ?m
AFTER EMIT "surface: " & ?before("volume") & ", solid: " & ?m("volume")