Sketches and constraints
A sketch is 2D geometry on a plane or a planar face, solved from its constraints. Features use a sketch's closed loops as profiles (profile = sketch.outline), its open chains as paths, and its points as positions.
runmat 0.7
std 1
part link {
input length : length = 60 mm
input radius : length = 8 mm
sketch s on origin.xy {
bottom = line(start = [0 mm, -8 mm], end = [60 mm, -8 mm])
right = arc(center = [60 mm, 0 mm], start = bottom.end, end = [60 mm, 8 mm])
top = line(start = right.end, end = [0 mm, 8 mm])
left = arc(center = [0 mm, 0 mm], start = top.end, end = bottom.start)
hole = circle(center = left.center, radius = 3 mm)
axis = line(start = left.center, end = right.center, construction)
constrain fix(axis.start)
constrain horizontal(axis)
constrain length(axis) = input.length
constrain tangent(bottom, right)
constrain tangent(top, left)
constrain parallel(bottom, top)
constrain equal(right, left)
constrain radius(right) = input.radius
constrain diameter(hole) = 6 mm
}
feature body = extrude(profile = sketch.s, distance = 5 mm)
output link = { body = feature.body.body }
}Planes
sketch <name> on <plane> { … } places the sketch:
| Plane | Example |
|---|---|
| An origin plane | on origin.xy, on origin.yz, on origin.zx |
| A datum plane | on plane.top_plane |
| A planar face | on feature.body.face.end |
A sketch on a face moves with the face when an earlier feature changes.
Entities
| Entity | Form |
|---|---|
| Line | l1 = line(start = [0 mm, 0 mm], end = [80 mm, 0 mm]) |
| Arc | a1 = arc(center = [0 mm, 0 mm], start = [10 mm, 0 mm], end = [0 mm, 10 mm]) |
| Circle | c1 = circle(center = [40 mm, 25 mm], radius = 5 mm) |
| Spline | lobe = spline(points = [[10 mm, 0 mm], [0 mm, 10 mm], [-10 mm, 0 mm]], closed) |
| Point | p1 = point(at = [3 mm, 4 mm]) |
- A point is
[x, y]with a unit on each coordinate, or[x, y] mmwith one unit after the list. - Shared points. Writing another entity's point (
start = bottom.end) makes the two the same point, so the loop stays closed as the solver moves it. Entity points arestart,endandcenter; a point entity's position isp1.at. - Construction geometry.
constructionafter an entity's arguments makes it a reference for constraints only; it never becomes part of a profile. - Sketch points are read elsewhere as
sketch.<sketch>.<entity>.<point>, such as a hole atsketch.marks.p1.at.
Constraints
constrain <relation> states a relation the solver keeps. A dimensional constraint takes its value after =, and the value may be any expression (= input.length, = 2 * input.radius).
| Constraint | Form |
|---|---|
| Fix | constrain fix(p1), constrain fix(l1.start) |
| Coincident | constrain coincident(l1.end, l2.start) |
| Horizontal, vertical | constrain horizontal(l1), constrain vertical(l2) |
| Parallel, perpendicular | constrain parallel(l1, l3), constrain perpendicular(l1, l2) |
| Tangent | constrain tangent(l1, a1) |
| Equal | constrain equal(a1, a2) |
| Midpoint | constrain midpoint(p1.at, l1): the point sits halfway along the line |
| Concentric, coradial | constrain concentric(c1, c2) (one center), constrain coradial(c1, a1) (one center and one radius) |
| Collinear | constrain collinear(l1, l5): both lines lie on one infinite line |
| Symmetric | constrain symmetric(l1.start, l2.end, axis): two points mirror each other in a line |
| Distance | constrain distance(l1.start, l2.end) = 60 mm |
| Length | constrain length(l1) = 80 mm |
| Radius, diameter | constrain radius(c1) = 5 mm, constrain diameter(c1) = 10 mm |
| Angle | constrain angle(l1, l2) = 90 deg |
| Limit | constrain limit(length(l3, value = 80 mm), min = 60 mm, max = 90 mm): a dimension that may move between bounds |
id = <name> names a constraint (constrain length(l1, id = span) = 80 mm), so a configuration or the editor can address it.
Solving
The check reports a sketch that is over-constrained (with the conflicting constraints), under-constrained (with the free directions), or has redundant constraints, and a profile that does not close (cad.sketch.open_profile). The editor writes the solver's last result in a solved { … } block inside the sketch, in SI units, so a file reopens without re-solving:
sketch s1 on origin.xy {
l1 = line(start = [0 mm, 0 mm], end = [80 mm, 0 mm])
c1 = circle(center = [40 mm, 25 mm], radius = 5 mm)
constrain horizontal(l1)
solved {
l1.start = [0, 0]
c1.radius = 0.005
}
}The solved block is a cache: editing the constraints re-solves the sketch and rewrites it.