Foremka scripting language reference
Everything about the language Foremka uses to build models from code, in the script console and in the assistant's answers. This page is generated from the same function catalog as the console hints, so it always matches the current version.
A script builds the model the same way the interface does: every function is one operation in the history. Run on an empty document it rebuilds the model from scratch; run on an existing one it appends operations at the end.
Basics
# comment to end of line
thickness = 12 # variable
side = param("side", 40) # document parameter, returns its value
b = box([80, 20, 40]) # positional argument
fillet(edges(b), radius: 3) # named argument after a colonNumbers may carry a unit: 12mm, 2.5cm, 1in, 30deg, 1.57rad.
Without a unit, lengths are millimetres and angles are degrees.
A sketch point is [x, y], a point or vector in space is [x, y, z].
Vectors add and scale: [10, 0, 0] * 2.
World
Up is Y, not Z. The constant up is [0, 1, 0], down is [0, -1, 0],
axes are x_axis, y_axis, z_axis. Base planes are plane.xy
(horizontal, normal up), plane.yz and plane.xz (both vertical). A sketch on
plane.xy therefore extrudes upwards, and box([80, 20, 40]) is 20 mm tall.
Control flow
if thickness > 10 {
print("thick")
} else {
print("thin")
}
for i in range(0, 5) {
hole(face(b, "top"), at: [10 + i * 15, 20], diameter: 5)
}
def rib_height(length) {
return length / 3
}Operators: + - * / % ^, comparisons < > <= >= == !=, and and, or, not.
Three things worth knowing
Bodies are results of operations.
b = extrude(sk, 10)yields a body andb = fillet(edges(b), 2)replaces it with the rounded one. An older variable still works: references follow the current shape of the body.Geometry is picked by description, not by number. Instead of remembering edge number seven you write
edges(b, dir: up)orfaces(b, kind: "cylinder", diameter: 6). Such a query survives a change of dimensions; an index does not.A sketch has its own coordinate system.
[0, 0]is its origin, also when it lies on a face of a body. An extrusion goes perpendicular to the sketch.
Example
thickness = param("thickness", 12)
plate = sketch(plane.xy) {
rect(center: [0, 0], width: 120, height: 80)
}
b = extrude(plate, thickness)
b = fillet(edges(b, dir: up), 8)
b = shell(b, 2, openings: faces(b, side: "top"))
for i in range(0, 4) {
b = hole(face(b, "bottom"), at: [-45 + i * 30, 0], diameter: 5, depth: 6)
}
name(b, "Base")Functions
Parameters
param
Stores a document parameter and returns its value. Dimensions built from that value, also computed from it (w / 2 + 3), are bound to the parameter and recompute when it changes in the parameters panel: primitive sizes and positions, extrude distances, revolve angles, fillet radii, thicknesses, patterns, sketch dimensions and the points of lines, rectangles, circles and polylines.
| parameter | type | description |
|---|---|---|
name (required) |
text | Parameter name, without spaces. |
value (required) |
any | A number or an expression in text, for example "thickness * 2". |
unit |
text | Parameter unit. Values: "mm", "deg", "unitless". Default mm. |
Returns: number: the resolved parameter value.
grubosc = param("grubosc", 12)
kat = param("pochylenie", 3, unit: "deg")
bok = param("bok", "grubosc * 4")Sketch
arc
An arc through three points: start, end and a point lying on the arc.
| parameter | type | description |
|---|---|---|
p1 (required) |
[x, y] | Arc start. |
p2 (required) |
[x, y] | Arc end. |
through (required) |
[x, y] | A point on the arc. |
construction |
true/false | Construction geometry: drawn with a dashed line, does not close regions and takes no part in operations. |
Returns: sketch entity.
arc([0, 0], [20, 0], [10, 6])arc_center
An arc about the given centre, from the start point to the end point, counter-clockwise.
| parameter | type | description |
|---|---|---|
center (required) |
[x, y] | Arc centre. |
start (required) |
[x, y] | Start point. |
end (required) |
[x, y] | End point. |
large |
true/false | Take the arc longer than a semicircle. An arc always runs counter-clockwise, so on the longer side the start and the end swap roles. Default false. |
construction |
true/false | Construction geometry: drawn with a dashed line, does not close regions and takes no part in operations. |
Returns: sketch entity.
center
Centre of a circle or an arc.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
entity (required) |
sketch entity | A circle or an arc. |
Returns: sketch point.
chamfer_2d
Cuts the corner between two sketch lines.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
a (required) |
sketch entity | First line. |
b (required) |
sketch entity | Second line. |
size (required) |
number | Distance of the cut from the corner. |
Returns: nothing.
circle
A circle about the given centre. The size is given by a radius or a diameter.
| parameter | type | description |
|---|---|---|
center (required) |
[x, y] | Circle centre. |
radius |
number | Radius. |
diameter |
number | Diameter. |
construction |
true/false | Construction geometry: drawn with a dashed line, does not close regions and takes no part in operations. |
Returns: sketch entity.
circle([0, 0], diameter: 20)
circle([10, 10], 5)circle_2pt
A circle through two points lying at the ends of a diameter.
| parameter | type | description |
|---|---|---|
p1 (required) |
[x, y] | First point. |
p2 (required) |
[x, y] | Second point. |
construction |
true/false | Construction geometry: drawn with a dashed line, does not close regions and takes no part in operations. |
Returns: sketch entity.
circle_3pt
A circle passing through three points.
| parameter | type | description |
|---|---|---|
p1 (required) |
[x, y] | First point. |
p2 (required) |
[x, y] | Second point. |
p3 (required) |
[x, y] | Third point. |
construction |
true/false | Construction geometry: drawn with a dashed line, does not close regions and takes no part in operations. |
Returns: sketch entity.
construction
Switches drawing to construction geometry and back. Holds until the end of the sketch block.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
on |
true/false | True turns construction mode on. Default true. |
Returns: nothing.
construction(true)
line([0,0], [50,0])
construction(false)end
End point of a line, an arc or a curve.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
entity (required) |
sketch entity | Sketch entity. |
Returns: sketch point.
fillet_2d
Rounds the corner between two sketch entities.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
a (required) |
sketch entity | First arm of the corner. |
b (required) |
sketch entity | Second arm of the corner. |
radius (required) |
number | Fillet radius. |
Returns: nothing.
intersect_curves
Inserts the curves and points where the given geometry crosses the sketch plane.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
target (required) |
any | A body, faces, edges, another sketch, an axis or a plane crossing the sketch plane. |
Returns: list of entities.
intersect_curves(b)
intersect_curves(faces(b, kind: "cylinder"))A face and a body give section curves, an edge and an axis a piercing point, a plane a common line. Geometry that does not touch the sketch plane is an error, because a quietly empty result would hide a mistake in the script.
line
A segment between two sketch points.
| parameter | type | description |
|---|---|---|
p1 (required) |
[x, y] | Start point [x, y]. |
p2 (required) |
[x, y] | End point [x, y]. |
construction |
true/false | Construction geometry: drawn with a dashed line, does not close regions and takes no part in operations. |
Returns: sketch entity.
a = line([0, 0], [80, 0])mirror_curves
Mirrors the given entities about a sketch line and ties the copies with a symmetry constraint.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
entities (required) |
sketch entities | Entities to mirror. |
line (required) |
sketch entity | The line serving as the mirror axis. |
Returns: number: how many entities were mirrored.
offset_curves
Offsets the given curves by a distance, creating a parallel contour.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
entities (required) |
sketch entities | Entities to offset. |
distance (required) |
number | Distance; a positive one offsets outwards from the contour. |
Returns: list of entities.
offset_curves(kontur, 3)pattern_rect
A grid pattern in the sketch: copies of the entities in rows and columns.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
entities (required) |
sketch entities | Entities to copy. |
cols (required) |
number | Number of columns including the original. |
rows |
number | Number of rows including the original. Default 1. |
dx |
number | Column spacing in millimetres. Default 0. |
dy |
number | Row spacing in millimetres. Default 0. |
Returns: nothing.
pattern_rect(otwor, cols: 4, rows: 2, dx: 20, dy: 15)pattern_ring
A circular pattern in the sketch: copies of the entities spread around a point.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
entities (required) |
sketch entities | Entities to copy. |
center (required) |
[x, y] | Centre of rotation in sketch coordinates. |
count (required) |
number | Number of copies including the original. |
angle |
number | Angular span in degrees. Default 360. |
Returns: nothing.
pattern_ring(otwor, [0, 0], count: 6)point
A standalone sketch point. Creates no region; serves as a reference for constraints and patterns.
| parameter | type | description |
|---|---|---|
at (required) |
[x, y] | Point position. |
construction |
true/false | Construction geometry: drawn with a dashed line, does not close regions and takes no part in operations. |
Returns: sketch entity.
polygon
A regular polygon inscribed in a circle or circumscribed about it.
| parameter | type | description |
|---|---|---|
center (required) |
[x, y] | Polygon centre. |
sides (required) |
number | Number of sides, at least three. |
radius |
number | Radius of the reference circle. |
diameter |
number | Diameter of the reference circle. |
inscribed |
true/false | True inscribes the polygon in the circle (vertices on the circle), false circumscribes it about the circle (sides tangent). Default true. |
angle |
number | Polygon rotation in degrees. Default 0. |
construction |
true/false | Construction geometry: drawn with a dashed line, does not close regions and takes no part in operations. |
Returns: list of entities.
polygon([0, 0], sides: 6, diameter: 20)polyline
A polyline through consecutive points. With the closing option gives a closed contour.
| parameter | type | description |
|---|---|---|
points (required) |
list | A list of points [[x, y], ...]. |
closed |
true/false | Close the polyline with a segment from the end back to the start. Default false. |
construction |
true/false | Construction geometry: drawn with a dashed line, does not close regions and takes no part in operations. |
Returns: list of entities.
polyline([[0,0], [40,0], [40,20], [0,20]], closed: true)project
Projects geometry onto the sketch plane along its normal. The projection stays linked to its source.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
target (required) |
any | Edges, faces, a body, another sketch (whole, one of its entities or a point), an axis, a plane or a point [x, y, z]. |
Returns: list of entities.
project(faces(b, side: "top"))
project(edges(b, dir: up))
project(sk1)A projection flattens the source along the sketch normal, so it always comes out. When you need the trace of geometry exactly on the plane, use intersect_curves.
rect
A rectangle. Given either by two opposite corners or by a centre with width and height.
| parameter | type | description |
|---|---|---|
p1 |
[x, y] | First corner. |
p2 |
[x, y] | Opposite corner. |
center |
[x, y] | Rectangle centre. |
width |
number | Width along the sketch X axis. |
height |
number | Height along the sketch Y axis. |
construction |
true/false | Construction geometry: drawn with a dashed line, does not close regions and takes no part in operations. |
Returns: list of four entities.
rect([0, 0], [80, 40])
rect(center: [0, 0], width: 80, height: 40)rect_3pt
A rotated rectangle: two points set one side, the third sets the height.
| parameter | type | description |
|---|---|---|
p1 (required) |
[x, y] | Start of the side. |
p2 (required) |
[x, y] | End of the side. |
p3 (required) |
[x, y] | A point setting the height. |
construction |
true/false | Construction geometry: drawn with a dashed line, does not close regions and takes no part in operations. |
Returns: list of four entities.
sketch
Creates a sketch on a plane and fills it with geometry from a block or from a list of entities.
| parameter | type | description |
|---|---|---|
plane (required) |
plane | A base plane, a construction plane or a flat face of a body. |
entities |
list | A list of entities, when no block is used. |
name |
text | Sketch name in the tree. |
Returns: sketch.
sk = sketch(plane.xy) {
rect([0, 0], [80, 40])
circle([40, 20], diameter: 10)
}
sk = sketch(face(b, "top"), [circle([0, 0], diameter: 6)])Constraints work only in the block form, because only there do entities have names.
spline
A free curve passing through the given points.
| parameter | type | description |
|---|---|---|
points (required) |
list | A list of points [[x, y], ...], at least two. |
closed |
true/false | Close the curve into a loop. Default false. |
control |
true/false | True treats the points as control poles the curve does not pass through. Default false. |
construction |
true/false | Construction geometry: drawn with a dashed line, does not close regions and takes no part in operations. |
Returns: sketch entity.
spline([[0,0], [20,15], [40,0]], closed: false)start
Start point of a line, an arc or a curve.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
entity (required) |
sketch entity | Sketch entity. |
Returns: sketch point.
text
Text set in a font: at a point, in a frame given by two corners, or along a sketch curve. Letters are closed contours, so the text extrudes and cuts like any profile.
| parameter | type | description |
|---|---|---|
content (required) |
text | The text; "\n" separates lines. |
at |
[x, y] | Point the text stands at (by halign and valign), or the first frame corner when to is given. Default [0, 0]. |
to |
[x, y] | Frame corner opposite to at; the text aligns inside the frame. |
height |
number | Capital letter height in millimetres. Without it the text fills the frame or a part of the curve, and at a point it is 5 mm. |
font |
text | Font by name, for example "Roboto", "Liberation Serif", "Black Ops One"; "Arial", "Times New Roman" and "Courier New" give fonts with the same character widths. Liberation Sans by default. |
font_file |
text | A TTF, OTF or WOFF font file instead of a font by name. |
bold |
true/false | Bold, when the font has that style. Default false. |
italic |
true/false | Italic; a font without a slanted style gets a 12° slant. Default false. |
halign |
text | Horizontal alignment. Values: "left", "center", "right". Default center. |
valign |
text | Vertical alignment (at a point and in a frame). Values: "top", "middle", "bottom". Default middle. |
angle |
number | Rotation of the text in degrees about at. Default 0. |
spacing |
number | Character spacing in percent of the font advance (0 as in the font, negative tightens). Default 0. |
flip_h |
true/false | Horizontal flip (mirrored text, for example for a stamp). Default false. |
flip_v |
true/false | Vertical flip. Default false. |
path |
sketch entity | Sketch curve (line, arc, circle, spline) the text runs along. |
side |
text | Text above the curve (outside on a circle) or below it. Values: "above", "below". Default above. |
fit |
true/false | Spread the characters over the whole curve length. Default false. |
Returns: sketch entity.
text("FOREMKA", at: [0, 0], height: 8, font: "Roboto", bold: true)
text("Pokrywa\nrev. 2", [-30, -10], [30, 10], font: "Liberation Serif")
c = circle([0, 0], 20)
text("NA OKRĘGU", path: c, height: 4)Text in a frame and along a curve can be edited later in the sketch by double-clicking, like text from the Text tool. extrude(sk, ...) extrudes the letter regions; in a sketch with a rectangle around the text the letters are holes in the plate.
trim
Removes the piece of a curve marked by a point, cutting it where other curves cross it.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
entity (required) |
sketch entity | Curve to trim. |
at (required) |
[x, y] | A point on the piece that should go away. |
Returns: nothing.
Constraints
angle
An angle dimension between two lines.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
a (required) |
sketch entity | First line. |
b (required) |
sketch entity | Second line. |
value (required) |
number | Angle in degrees. |
Returns: nothing.
circle_line_distance
A dimension for the distance from the rim of a circle to a line. For a dimension to the centre use point_line_distance.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
circle (required) |
sketch entity | A circle or an arc. |
line (required) |
sketch entity | Line. |
value (required) |
number | Distance from the rim to the line, in millimetres. |
Returns: nothing.
coincident
Merges two sketch points into one. The strongest constraint there is: the points stop existing separately.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
a (required) |
point | First point. |
b (required) |
point | Second point. |
Returns: nothing.
coincident(end(a), start(b))diameter
A diameter dimension of a circle.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
circle (required) |
sketch entity | Circle. |
value (required) |
number | Diameter in millimetres. |
Returns: nothing.
distance
A distance dimension between two points. The value you type drives the geometry.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
a (required) |
point | First point. |
b (required) |
point | Second point. |
value (required) |
number | Distance in millimetres. |
Returns: nothing.
distance(start(a), end(a), 80)equal
Forces two lines to the same length, or two circles to the same radius.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
a (required) |
sketch entity | First entity. |
b (required) |
sketch entity | Second entity. |
Returns: nothing.
equal(a, b)h_distance
A horizontal distance dimension between two points.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
a (required) |
point | First point. |
b (required) |
point | Second point. |
value (required) |
number | Distance in millimetres. |
Returns: nothing.
horizontal
Forces a line to lie horizontally, or a horizontal straight line through two points. Horizontal is measured in sketch coordinates.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
a (required) |
any | A line or the first point. |
b |
point | The second point, when the first argument was a point. |
Returns: nothing.
horizontal(a)
horizontal(center(c1), center(c2))midpoint
Forces a point to lie halfway between two others.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
mid (required) |
point | Middle point. |
a (required) |
point | First end point. |
b (required) |
point | Second end point. |
Returns: nothing.
parallel
Forces two lines to be parallel.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
a (required) |
sketch entity | First entity. |
b (required) |
sketch entity | Second entity. |
Returns: nothing.
parallel(a, b)perpendicular
Forces two lines to be perpendicular.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
a (required) |
sketch entity | First entity. |
b (required) |
sketch entity | Second entity. |
Returns: nothing.
perpendicular(a, b)point_line_distance
A dimension for the distance from a point to a line.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
point (required) |
point | Point. |
line (required) |
sketch entity | Line. |
value (required) |
number | Distance in millimetres. |
Returns: nothing.
point_on
Forces a point to lie on a line or on a circle.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
point (required) |
point | Point. |
curve (required) |
sketch entity | A line or a circle. |
Returns: nothing.
radius
A radius dimension of a circle or an arc.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
circle (required) |
sketch entity | A circle or an arc. |
value (required) |
number | Radius in millimetres. |
Returns: nothing.
symmetric
Forces two points to be symmetric about a line.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
a (required) |
point | First point. |
b (required) |
point | Second point. |
line (required) |
sketch entity | Axis of symmetry. |
Returns: nothing.
tangent
Forces a line to be tangent to a circle, or two circles to be tangent to each other.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
a (required) |
sketch entity | First entity. |
b (required) |
sketch entity | Second entity. |
Returns: nothing.
tangent(l, c)v_distance
A vertical distance dimension between two points.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
a (required) |
point | First point. |
b (required) |
point | Second point. |
value (required) |
number | Distance in millimetres. |
Returns: nothing.
vertical
Forces a line to lie vertically, or a vertical straight line through two points.
Works only inside a sketch block.
| parameter | type | description |
|---|---|---|
a (required) |
any | A line or the first point. |
b |
point | The second point, when the first argument was a point. |
Returns: nothing.
Selection
axis
An axis given by a point and a direction. For revolve and circular pattern.
| parameter | type | description |
|---|---|---|
origin (required) |
[x, y, z] | A point on the axis. |
direction (required) |
[x, y, z] | Axis direction. |
Returns: axis.
revolve(sk, axis([0,0,0], up), 360)axis_of
An axis taken from geometry: from a straight edge its direction, from a circular one or from a cylindrical face the axis of revolution.
| parameter | type | description |
|---|---|---|
geometry (required) |
any | An edge or a face. |
Returns: axis.
pattern_circular(b, axis_of(face(b, kind: "cylinder")), count: 6)bodies
A list of all visible bodies in the document.
Returns: list of bodies.
for b in bodies() { print(b.name) }body
A body by its name in the tree. Without an argument gives the most recently created one.
| parameter | type | description |
|---|---|---|
name |
text | Body name, for example "Body 1". |
Returns: body.
b = body("Bryła 1")edges
Edges of a body matching every given condition. Without conditions gives every edge.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body. |
kind |
text | Edge kind. Values: "line", "circle", "arc", "curve". |
dir |
[x, y, z] | A direction; keeps straight edges parallel to it. |
perpendicular |
[x, y, z] | A direction; keeps edges perpendicular to it. |
length |
number | Exact length in millimetres. |
min_length |
number | Smallest length. |
max_length |
number | Largest length. |
radius |
number | Radius of a circle or an arc. |
diameter |
number | Diameter of a circle or an arc. |
near |
[x, y, z] | A point in space; keeps elements lying close to it. |
within |
number | Search radius for "near", in millimetres. Default 1. |
index |
any | A BREP index or a list of them. A brittle way to write it: survives only until the next change to the model. |
where |
function | Your own condition: a function taking the properties of an element and returning true or false. |
sort |
text | Result order, for example "z" or "-area". A minus reverses it. |
limit |
number | Keep at most this many elements. |
Returns: edge set.
fillet(edges(b, dir: up), radius: 3)
chamfer(edges(b, kind: "circle", diameter: 6), 0.5)
edges(b, where: def(e) { return e.length > 20 and e.mid.z > 0 })Tangent, seam and degenerate edges are skipped, just like when picking with the mouse.
face
A single face. Short for faces(...) with the requirement that exactly one comes back; on more than one the script stops instead of quietly taking the first that fits.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body. |
side |
text | Side of the body. Values: "top", "bottom", "front", "back", "left", "right". |
kind |
text | Surface kind. Values: "plane", "cylinder", "cone", "sphere", "torus", "spline", "surface". |
normal |
[x, y, z] | Normal direction. |
diameter |
number | Diameter of a cylinder or a sphere. |
internal |
true/false | True picks the faces of holes. |
near |
[x, y, z] | A point in space; keeps elements lying close to it. |
within |
number | Search radius for "near", in millimetres. Default 1. |
index |
any | A BREP index or a list of them. A brittle way to write it: survives only until the next change to the model. |
where |
function | Your own condition: a function taking the properties of an element and returning true or false. |
sort |
text | Result order, for example "z" or "-area". A minus reverses it. |
limit |
number | Keep at most this many elements. |
Returns: face set holding exactly one face.
sk = sketch(face(b, "top"))
hole(face(b, "top"), at: [10, 10], diameter: 5)faces
Faces of a body matching every given condition.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body. |
kind |
text | Surface kind. Values: "plane", "cylinder", "cone", "sphere", "torus", "spline", "surface". |
normal |
[x, y, z] | Normal direction; keeps faces pointing that way. |
side |
text | The outermost face on the given side of the body. Values: "top", "bottom", "front", "back", "left", "right". |
area |
number | Exact area in square millimetres. |
min_area |
number | Smallest area. |
max_area |
number | Largest area. |
radius |
number | Radius of a cylinder, a cone or a sphere. |
diameter |
number | Diameter of a cylinder or a sphere. |
internal |
true/false | True picks the faces of holes, false the outer surfaces. |
near |
[x, y, z] | A point in space; keeps elements lying close to it. |
within |
number | Search radius for "near", in millimetres. Default 1. |
index |
any | A BREP index or a list of them. A brittle way to write it: survives only until the next change to the model. |
where |
function | Your own condition: a function taking the properties of an element and returning true or false. |
sort |
text | Result order, for example "z" or "-area". A minus reverses it. |
limit |
number | Keep at most this many elements. |
Returns: face set.
shell(b, 2, openings: faces(b, side: "top"))
faces(b, kind: "cylinder", diameter: 6, internal: true)
faces(b, normal: up, min_area: 100)find_sketch
A sketch by its name in the tree. Without an argument gives the most recently created one.
| parameter | type | description |
|---|---|---|
name |
text | Sketch name, for example "Sketch1". |
Returns: sketch.
sk = find_sketch("Sketch1")
b = extrude(find_sketch(), 10)The counterpart of "body" for sketches: reaches a sketch from an earlier run of a script, where the variable holding it no longer exists.
plane_from
A plane given by a point and a normal.
| parameter | type | description |
|---|---|---|
origin (required) |
[x, y, z] | A point on the plane. |
normal (required) |
[x, y, z] | Plane normal. |
Returns: plane.
mirror(b, plane_from([0,0,0], x_axis))profile
Sketch regions to extrude or revolve. Without further conditions takes every closed region of the sketch.
| parameter | type | description |
|---|---|---|
sketch (required) |
sketch | Sketch. |
near |
[x, y] | A point in sketch coordinates; keeps the region that point lies in. |
index |
any | A region index or a list of them, counting from zero. |
min_area |
number | Smallest region area. |
max_area |
number | Largest region area. |
Returns: profile.
extrude(profile(sk, index: 0), 10)Usually the sketch alone is enough: extrude(sk, 10) takes all of its regions.
sketches
A list of all sketches in the document.
Returns: list of sketches.
print(count(sketches()))Primitives
box
A box with the given dimensions.
| parameter | type | description |
|---|---|---|
size (required) |
[x, y, z] | Dimensions [x, y, z] in millimetres. |
at |
[x, y, z] | Starting corner. Default [0, 0, 0]. |
Returns: body.
b = box([80, 40, 20])cylinder
A cylinder with a vertical axis.
| parameter | type | description |
|---|---|---|
radius |
number | Radius. |
height (required) |
number | Height. |
diameter |
number | Diameter, instead of the radius. |
at |
[x, y, z] | Centre of the base. Default [0, 0, 0]. |
Returns: body.
b = cylinder(diameter: 30, height: 50)gear_rack
A gear rack with straight teeth, the partner of a spur_gear with the same module and pressure angle. It lies on the horizontal plane: the rack runs along +X, the teeth point to -Z and the width grows upwards.
| parameter | type | description |
|---|---|---|
teeth (required) |
number | Number of teeth, from 1 to 1000; the rack length is teeth * pi * module. |
module |
number | Module in mm: tooth pitch divided by pi. |
diametral_pitch |
number | Diametral pitch (teeth per inch) instead of the module, for an inch rack. |
thickness |
number | Rack width (upwards, along the gear axis). Default 10. |
height |
number | Height from the bottom to the pitch line; none = 2.5 module + 10 mm. |
pressure_angle |
number | Pressure angle in degrees, usually 20 (sometimes 14.5 or 25). Default 20. |
backlash |
number | Backlash of the pair along the pitch line; the rack gives up half of it. Default 0. |
fillet |
number | Root fillet radius; none = 0.375 of the module. |
at |
[x, y, z] | Start of the pitch line on the bottom face. Default [0, 0, 0]. |
Returns: body.
r = gear_rack(24, 2, thickness: 10, at: [-75.4, 0, 20])
p = spur_gear(20, 2, thickness: 10, hole: 8)A gear with pitch radius r meshes with the rack when its centre lies r from the pitch line on the teeth side: a rack with at: [x, 0, r] fits a gear at the origin. Tooth number k has its axis at x + (k + 1/2) * pi * module, so both ends of the rack fall in the middle of a gap. Turning the gear by an angle a (radians) moves the rack by a * r.
sphere
A sphere.
| parameter | type | description |
|---|---|---|
radius |
number | Radius. |
diameter |
number | Diameter, instead of the radius. |
at |
[x, y, z] | Sphere centre. Default [0, 0, 0]. |
Returns: body.
spur_gear
A spur gear with straight teeth and an involute profile (ISO 53 basic rack). It lies on the horizontal plane with a vertical axis, tooth number 0 points along +X.
| parameter | type | description |
|---|---|---|
teeth (required) |
number | Number of teeth, from 3 to 300. |
module |
number | Module in mm: pitch diameter divided by the number of teeth. |
diametral_pitch |
number | Diametral pitch (teeth per inch of pitch diameter) instead of the module, for an inch gear. |
thickness |
number | Gear thickness. Default 10. |
pressure_angle |
number | Pressure angle in degrees, usually 20 (sometimes 14.5 or 25). Default 20. |
backlash |
number | Backlash of the pair along the pitch circle; each gear gives up half of it. Default 0. |
fillet |
number | Root fillet radius; none = 0.375 of the module. One that is too large shrinks to the largest that fits between the teeth. |
hole |
number | Shaft hole diameter; 0 = no hole. Default 0. |
at |
[x, y, z] | Centre of the bottom face. Default [0, 0, 0]. |
Returns: body.
g = spur_gear(24, 2, thickness: 8, hole: 8)
p = spur_gear(13, 2, thickness: 8, at: [37, 0, 0])A pair meshes at a centre distance of module * (z1 + z2) / 2. A gear placed along +X from the other faces it with a gap when its tooth count is odd; with an even count rotate it by half a pitch first: move(p, rotate: 180 / z, axis: up), then move it into place. Below 17 teeth (20°) the teeth are not undercut, so a small pinion also touches a large gear below its base circle.
torus
A torus with a vertical axis.
| parameter | type | description |
|---|---|---|
radius (required) |
number | Major radius, from the axis to the centre of the tube. |
tube (required) |
number | Radius of the tube. |
at |
[x, y, z] | Torus centre. Default [0, 0, 0]. |
Returns: body.
Solids
emboss
Raises or recesses a sketch profile on a body face, curved ones too (text or a logo on a cylinder).
| parameter | type | description |
|---|---|---|
face (required) |
any | The face the profile lies on (from a face set the first one counts) or a body together with the "at" point. |
profile (required) |
profile | Sketch or its regions. |
depth (required) |
number | Depth. |
deboss |
true/false | Recess into the face instead of raising above it. Default false. |
wrap |
true/false | Wrap along the surface without stretching; false projects the profile along the sketch normal. Default true. |
offset_x |
number | Offset along the sketch X axis, along the surface when wrapping. Default 0. |
offset_y |
number | Offset along the sketch Y axis. Default 0. |
angle |
number | Rotation of the profile around its centre, in degrees. Default 0. |
at |
[x, y, z] | A point lying on the face when a body is given instead of a face; picks the nearest face. |
Returns: body.
emboss(face(walec, kind: "cylinder"), napis, 1)
emboss(walec, napis, 1, at: [0, 20, 20])
emboss(face(b, "top"), logo, 0.5, deboss: true)The reference point is the centre of the profile projected along the sketch normal onto the face, so draw the sketch on a plane facing the face (for a cylinder: through its axis or tangent to it).
extrude
Extrudes a profile perpendicular to its plane. The profile is a sketch, its selected regions or a face of a body (then it works as a face extrusion).
| parameter | type | description |
|---|---|---|
profile (required) |
profile | A sketch, sketch regions or a face. |
distance (required) |
number | Extrusion length; a negative one goes the other way. |
direction |
text | "one" extrudes one way, "symmetric" half of it each way, "two" separately in each. Values: "one", "symmetric", "two". Default one. |
distance2 |
number | The second length with direction: "two". |
op |
text | What to do with the target bodies: "new" creates a separate body, "join" adds material, "cut" removes it, "intersect" keeps the common part. Values: "new", "join", "cut", "intersect", "auto". Default new. |
target |
body or list of bodies | The body or bodies the boolean operation runs on. Required for "join", "cut" and "intersect". |
to |
plane | Instead of a length: a plane or a face where the extrusion should stop. |
offset |
number | Offset from the target object. Default 0. |
through_all |
true/false | Instead of a length: through the whole target bodies, towards the sign of the distance or both ways with direction: "symmetric". Only with op: "cut" or "intersect". Default false. |
solid |
true/false | False gives a surface instead of a solid; the profile may then be open. Default true. |
Returns: body or list of bodies.
b = extrude(sk, 20)
extrude(sk, -10, op: "cut", target: b)
extrude(sk, -1, op: "cut", target: b, through_all: true)
extrude(face(b, "top"), 5, op: "join", target: b)
extrude(sk, 0, to: face(other, "bottom"), offset: 1)An extrusion from a sketch made on a face of a body adds or removes material by default, depending on the sign of the distance.
loft
Spans a body between profiles on different planes, in the given order.
| parameter | type | description |
|---|---|---|
profiles (required) |
list | A list of profiles, at least two. |
closed |
true/false | Close into a loop: the last profile joins the first. Default false. |
ruled |
true/false | True joins the profiles with straight segments instead of smoothly. Default false. |
solid |
true/false | False gives a surface. Default true. |
twist |
number | Twist: sections between the profiles turn around their own center, by this many degrees in total from the first to the last profile. Not combined with closed. Default 0. |
op |
text | What to do with the target bodies: "new" creates a separate body, "join" adds material, "cut" removes it, "intersect" keeps the common part. Values: "new", "join", "cut", "intersect", "auto". Default new. |
target |
body or list of bodies | The body or bodies the boolean operation runs on. Required for "join", "cut" and "intersect". |
Returns: body or list of bodies.
b = loft([dol, srodek, gora])
b = loft([dol, gora], twist: 90)pipe
A pipe of circular section along a path from a sketch.
| parameter | type | description |
|---|---|---|
path (required) |
sketch | Sketch holding the path. |
diameter |
number | Pipe diameter. |
radius |
number | Radius, instead of the diameter. |
Returns: body.
b = pipe(sciezka, diameter: 12)project_to_surface
Lays sketch curves onto body faces, curved ones too. The result is a body of curves only, for example a face split line.
| parameter | type | description |
|---|---|---|
faces (required) |
any | Faces of one body, or a body together with the "at" points. |
curves (required) |
profile | Sketch, its regions (outlines, letters of text too) or chosen curves. A sketch without regions gives its open curves. |
mode |
text | "vector" projects along the sketch normal, "closest" to the nearest point of the face. Values: "vector", "closest". Default vector. |
at |
any | A point or a list of points lying on the faces when a body is given instead of faces. |
Returns: curve body.
k = project_to_surface(face(walec, kind: "cylinder"), napis)
split_face(face(walec, kind: "cylinder"), k)Curves add no material. They serve as a face split tool or a reference; emboss puts material on the face.
revolve
Revolves a profile about an axis.
| parameter | type | description |
|---|---|---|
profile (required) |
profile | A sketch or its regions. |
axis (required) |
axis | Axis of revolution: an axis, an edge or a direction. |
angle |
number | Angle of revolution in degrees; 360 gives a full body of revolution. Default 360. |
start_angle |
number | Rotation of the profile before it starts, in degrees. Default 0. |
pitch |
number | Pitch: when given, makes a profile thread, a helical revolve in which the profile moves along the axis by this much per turn. The angle is then ignored. |
length |
number | Length of the profile thread along the axis; negative goes the other way. Required together with pitch. |
left_hand |
true/false | Left-handed profile thread. Default false. |
trim |
true/false | Profile thread with op: "join": the tooth is trimmed flush with the ends of the target body; false leaves it sticking out. Default true. |
solid |
true/false | False gives a surface of revolution from the sketch curves; the profile may then be open. Default true. |
op |
text | What to do with the target bodies: "new" creates a separate body, "join" adds material, "cut" removes it, "intersect" keeps the common part. Values: "new", "join", "cut", "intersect", "auto". Default new. |
target |
body or list of bodies | The body or bodies the boolean operation runs on. Required for "join", "cut" and "intersect". |
Returns: body or list of bodies.
b = revolve(sk, axis([0,0,0], up), 360)
gwint = revolve(trapez, axis([0,0,0], up), pitch: 4, length: 30, op: "join", target: pret)
czasza = revolve(luk, axis([0,0,0], up), 360, solid: false)rib
A rib from an open profile: it grows towards the body and stops where it meets it.
| parameter | type | description |
|---|---|---|
body (required) |
body | The body the rib is attached to. |
profile (required) |
sketch | Sketch with the open profile of the rib. |
thickness (required) |
number | Rib thickness. |
direction |
[x, y, z] | The direction the profile grows in. Without it, worked out from the geometry. |
Returns: body.
sweep
Sweeps a profile along a path from another sketch.
| parameter | type | description |
|---|---|---|
profile (required) |
profile | Profile sketch or one of its regions. |
path (required) |
sketch | Sketch holding the path. |
solid |
true/false | False gives a surface from an open profile. Default true. |
frenet |
true/false | The profile turns with the twist of the path (Frenet mode); needed on a helix, otherwise the profile leaves the plane of the axis. Default false. |
rail |
sketch | Sketch holding the guide rail: its distance from the path scales the profile and its direction turns the profile around the path. |
scale |
text | How the rail changes the profile: "scale" scales it uniformly, "stretch" only toward the rail, "none" only turns it. Values: "scale", "stretch", "none". Default scale. |
twist |
number | Rotation of the profile around the path over its whole length, in degrees. Default 0. |
spin |
number | Rotation of the profile around its own center over the whole path, in degrees. Default 0. |
orientation |
text | "perpendicular" keeps the profile perpendicular to the path, "parallel" moves it without turning. Values: "perpendicular", "parallel". Default perpendicular. |
Returns: body or list of bodies.
b = sweep(profil, sciezka)
filar = sweep(kwadrat, os, rail: sylwetka, twist: 120, spin: 180)web
A web from an open profile: unlike a rib it enters the body along its whole length.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body. |
profile (required) |
sketch | Sketch with the profile of the web. |
thickness (required) |
number | Web thickness. |
direction |
[x, y, z] | The direction the profile grows in. |
Returns: body.
Modify
chamfer
Cuts the given edges.
| parameter | type | description |
|---|---|---|
edges (required) |
edges | Edges to cut. |
distance (required) |
number | Distance of the cut. |
distance2 |
number | A second distance; given, it makes the chamfer asymmetric. |
Returns: body.
b = chamfer(edges(b, kind: "circle", diameter: 8), 0.5)copy
A copy of the body in the same place. The original stays.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body to copy. |
Returns: body.
druga = move(copy(b), [40, 0, 0])draft
Tapers the given faces relative to the pull direction. For cast and moulded parts.
| parameter | type | description |
|---|---|---|
faces (required) |
faces | Faces to taper. |
angle (required) |
number | Draft angle in degrees; a negative one reverses the taper. |
neutral (required) |
plane | Neutral plane: the section whose size does not change. |
pull |
[x, y, z] | Pull direction. Without it, taken from the normal of the neutral plane. |
Returns: body.
b = draft(faces(b, kind: "plane", normal: x_axis), 3, neutral: face(b, "bottom"))fillet
Rounds the given edges.
| parameter | type | description |
|---|---|---|
edges (required) |
edges | Edges to round. |
radius (required) |
number | Fillet radius. |
radius2 |
number | The second radius: in "variable" mode the radius at the end of the edge, in "elliptic" the reach on the second face. |
mode |
text | What the second radius means. Values: "variable", "elliptic". Default variable. |
Returns: body.
b = fillet(edges(b, dir: up), 3)
fillet(edges(b, kind: "circle"), radius: 1)A fillet consumes the source body, the same as when working with the mouse. When the radius is too large for the geometry, the operation does not come out and the script reports an error.
hole
Drills a hole in a face of a body: simple, counterbored or countersunk, optionally threaded.
| parameter | type | description |
|---|---|---|
face (required) |
faces | The face the hole starts in. |
at (required) |
any | Hole centre: a point [x, y] in the coordinates of that face, or a point [x, y, z] in space. |
diameter |
number | Hole diameter. |
depth |
number | Depth; without it the hole goes through. |
type |
text | Hole kind. Values: "simple", "counterbore", "countersink". Default simple. |
drill_point |
true/false | The drill cone at the bottom of a blind hole. Default false. |
cb_diameter |
number | Counterbore diameter. |
cb_depth |
number | Counterbore depth. |
cs_diameter |
number | Diameter at the mouth of the countersink. |
cs_angle |
number | Cone angle in degrees. Default 90. |
thread |
text | Thread designation, for example "M6". The hole diameter then comes from the standard. |
thread_length |
number | Thread length from the mouth; without it the thread runs the whole depth. |
Returns: body.
b = hole(face(b, "top"), at: [10, 10], diameter: 6, depth: 12)
b = hole(face(b, "top"), at: [0, 0], thread: "M8")
b = hole(face(b, "top"), at: [20, 0], diameter: 5, type: "countersink", cs_diameter: 10)move
Moves and rotates a body.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body. |
by |
[x, y, z] | Translation [x, y, z]. Default [0, 0, 0]. |
rotate |
number | Rotation angle in degrees. |
axis |
axis | Axis of rotation. |
around |
[x, y, z] | The point the rotation happens about. Without it, the centre of the axis. |
Returns: body.
move(b, [0, 0, 25])
move(b, rotate: 45, axis: up)offset_body
Offsets every face of a body at once, fillets and holes included. A negative distance shrinks the body and enlarges holes: compensation for 3D print spread.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body to offset. |
distance (required) |
number | Offset; a positive one grows the body, a negative one shrinks it. |
corners |
text | Corners where the offset faces move apart: "sharp" extends the faces until they meet, "round" rounds them with a radius equal to the offset. Values: "sharp", "round". Default sharp. |
Returns: body.
b = offset_body(b, -0.1)
b = offset_body(b, 0.5, corners: "round")scale
Scales a body; separate factors per axis give a non-uniform scaling.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body. |
factor (required) |
any | Factor: one number or [sx, sy, sz]. |
center |
[x, y, z] | The point that stays put. Default [0, 0, 0]. |
Returns: body.
scale(b, 2)
scale(b, [2, 1, 1])shell
Hollows a body out, leaving a wall of the given thickness. The given faces are removed and become openings; without them the shell stays closed, with a cavity inside.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body to hollow out. |
thickness (required) |
number | Wall thickness. |
openings |
faces | Faces to remove. Without them the shell stays closed. |
corners |
text | Inner corners: "round" rounds them with a radius equal to the thickness, "sharp" extends the walls until they meet. Values: "round", "sharp". Default round. |
Returns: body.
b = shell(b, 2, openings: faces(b, side: "top"))
b = shell(b, 2)thicken
Gives thickness to a surface or to the given faces, turning them into a solid.
| parameter | type | description |
|---|---|---|
target (required) |
any | A surface body or a set of faces. |
thickness (required) |
number | Thickness. |
thickness2 |
number | Thickness on the opposite side. |
flip |
true/false | Flips the side the thickness grows on. Default false. |
Returns: body.
b = thicken(powierzchnia, 2)thread
Cuts a thread on a cylindrical face: on a shaft from the outside, in a hole from the inside.
| parameter | type | description |
|---|---|---|
face (required) |
faces | Cylindrical face. |
standard (required) |
text | Designation from the thread library, for example "M10x1.5". |
length |
number | Thread length; without it the whole face. |
offset |
number | Offset of the thread start along the axis. Default 0. |
modeled |
true/false | True cuts the real profile, false only draws the thread in the preview. Default true. |
fit |
true/false | True takes only the profile (pitch, angle, depth) from the standard and lays it on the cylinder's diameter. False resizes the cylinder to the standard's diameter. Default false. |
chamfer |
text | 45° chamfer at the thread end: "start", "end" or "both". The start is the end of the face with the lower coordinate along the axis. |
chamfer_size |
number | Chamfer size; without it equal to the thread depth (the edge goes down to the minor diameter). |
Returns: body.
b = thread(face(b, kind: "cylinder", diameter: 10), "M10")
b = thread(face(b, kind: "cylinder", diameter: 75), "M75x2", fit: true)
b = thread(face(b, kind: "cylinder", diameter: 10), "M10", chamfer: "end")Boolean operations
cut
Subtracts the tool bodies from the target body.
| parameter | type | description |
|---|---|---|
target (required) |
body | The body material is taken from. |
tools (required) |
body or list of bodies | The body or bodies subtracted. |
keep |
true/false | Leave the tools after the operation. Default false. |
Returns: body or list of bodies.
b = cut(korpus, wiertlo)intersect
Keeps the common part of the bodies.
| parameter | type | description |
|---|---|---|
target (required) |
body | First body. |
tools (required) |
body or list of bodies | The second body or a list of them. |
keep |
true/false | Leave the source bodies. Default false. |
Returns: body or list of bodies.
mirror
Mirrors bodies about a plane. The originals stay.
| parameter | type | description |
|---|---|---|
bodies (required) |
body or list of bodies | A body or a list of bodies. |
plane (required) |
plane | Mirror plane. |
features |
list | Instead of the whole body, mirror these history features, for example a cut; the result goes onto the given body. |
Returns: body or list of bodies.
mirror(b, plane.yz)
mirror(b, plane.yz, features: [wyciecie])split_body
Splits a body with a plane or a tool (a surface, also a bent one, or another body) into separate bodies.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body to split. |
plane |
plane | Cutting plane; leave it out when you give a tool. |
tool |
body | Instead of a plane: a surface or a body that cuts with its whole shape and stays untouched. A surface has to pass through the body. |
Returns: list of bodies.
czesci = split_body(b, plane.xy)
czesci = split_body(b, tool: zagieta)union
Joins bodies into one.
| parameter | type | description |
|---|---|---|
target (required) |
body | The body whose name and colour the result takes over. |
tools (required) |
body or list of bodies | The body or bodies joined to it. |
keep |
true/false | Leave the source bodies next to the result. Default false. |
Returns: body or list of bodies.
b = union(podstawa, wspornik)Patterns
pattern_circular
Copies a body around an axis.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body to copy. |
axis (required) |
axis | Pattern axis. |
count (required) |
number | Number of instances including the original. |
angle |
number | Angular span in degrees. Default 360. |
features |
list | Instead of the whole body, copy these history features. |
Returns: body or list of bodies.
pattern_circular(b, axis([0,0,0], up), count: 6)pattern_linear
Copies a body along a direction.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body to copy. |
direction (required) |
axis | Pattern direction. |
count (required) |
number | Number of instances including the original. |
distance (required) |
number | Spacing or overall span, depending on "spacing". |
spacing |
true/false | True treats the distance as the spacing between neighbours, false as the span of the whole pattern. Default true. |
features |
list | Instead of the whole body, copy these history features, for example a hole. |
direction2 |
axis | Second direction: the whole row is copied along it as well, giving a grid. |
count2 |
number | Number of rows along the second direction. Default 2. |
distance2 |
number | Spacing or span along the second direction, following the same "spacing". |
Returns: body or list of bodies.
pattern_linear(b, x_axis, count: 5, distance: 20)
pattern_linear(b, x_axis, count: 4, distance: 15, direction2: y_axis, count2: 3, distance2: 10)pattern_path
Copies a body along a path from a sketch.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body to copy. |
path (required) |
sketch | Sketch holding the path. |
count (required) |
number | Number of instances. |
distance (required) |
number | Spacing or overall span. |
spacing |
true/false | True treats the distance as spacing. Default true. |
follow |
true/false | True rotates the copies with the tangent of the path. Default true. |
Returns: body or list of bodies.
Faces
delete_face
Removes the given faces, closing the body with the neighbouring ones. For taking off fillets and chamfers.
| parameter | type | description |
|---|---|---|
faces (required) |
faces | Faces to remove. |
Returns: body.
offset_face
Offsets the given faces by a distance, changing the size of the body.
| parameter | type | description |
|---|---|---|
faces (required) |
faces | Faces to offset. |
distance (required) |
number | Offset; a positive one adds material. |
Returns: body.
replace_face
Replaces the given faces with another surface.
| parameter | type | description |
|---|---|---|
faces (required) |
faces | Faces to replace. |
tool (required) |
body | The surface taking their place; it must cut all the way through the body. |
Returns: body.
split_face
Splits faces with another shape, without changing the volume.
| parameter | type | description |
|---|---|---|
faces (required) |
faces | Faces to split. |
tool (required) |
body | The splitting body, surface or curves from project_to_surface; it stays untouched. |
Returns: body.
Surfaces
boundary_fill
Spans a surface across the given edges of bodies.
| parameter | type | description |
|---|---|---|
edges (required) |
edges | Boundary edges, at least two. |
Returns: surface body.
extend_surface
Extends a surface at the given edges.
| parameter | type | description |
|---|---|---|
edges (required) |
edges | Edges to extend. |
length (required) |
number | Length of the extension. |
natural |
true/false | True extends following the curvature, false linearly along the tangent. Default true. |
Returns: surface body.
offset_surface
Creates a surface offset from the given one. The source stays.
| parameter | type | description |
|---|---|---|
surface (required) |
body | Source surface. |
distance (required) |
number | Distance; the sign decides the side. |
mode |
text | "simple" offsets each face on its own and is more robust, "join" closes the neighbours up. Values: "simple", "join". Default simple. |
join_type |
text | How to close up in "join" mode. Values: "arc", "intersection". Default arc. |
Returns: surface body.
patch
Fills a closed sketch contour with a surface.
| parameter | type | description |
|---|---|---|
boundary (required) |
sketch | Sketch with a closed contour. |
Returns: surface body.
stitch
Stitches surfaces into a shell, and into a solid when the result comes out watertight.
| parameter | type | description |
|---|---|---|
surfaces (required) |
body or list of bodies | Surfaces to stitch, at least two. |
tolerance |
number | Stitching tolerance; zero takes the default. Default 0. |
solid |
true/false | Close into a solid when the shell came out watertight. Default true. |
Returns: body.
trim_surface
Trims a surface with another shape, keeping the piece marked by a point.
| parameter | type | description |
|---|---|---|
surface (required) |
body | The surface being trimmed. |
tool (required) |
body | Cutting tool; it stays untouched. |
keep (required) |
[x, y, z] | A point inside the piece that should remain. |
invert |
true/false | Keep everything except the marked piece. Default false. |
Returns: surface body.
unstitch
Breaks a shape apart into separate faces.
| parameter | type | description |
|---|---|---|
target (required) |
any | A body or selected faces. |
Returns: list of surface bodies.
Construction geometry
construction_axis
A construction axis in the tree, visible in the scene.
| parameter | type | description |
|---|---|---|
origin (required) |
[x, y, z] | A point on the axis. |
direction (required) |
[x, y, z] | Axis direction. |
name |
text | Name in the tree. Default Oś. |
Returns: construction axis.
construction_point
A construction point in the tree.
| parameter | type | description |
|---|---|---|
position (required) |
[x, y, z] | Point position. |
name |
text | Name in the tree. Default Punkt. |
Returns: construction point.
offset_plane
A construction plane offset parallel to the given one. Lands in the tree and can be sketched on.
| parameter | type | description |
|---|---|---|
base (required) |
plane | Base plane or face. |
distance (required) |
number | Offset along the normal, in millimetres. |
Returns: construction plane.
p = offset_plane(plane.xy, 25)
sk = sketch(p)plane_along_path
A construction plane perpendicular to a sketch curve at the given position along its length.
| parameter | type | description |
|---|---|---|
path (required) |
sketch entity | Sketch curve. |
at |
number | Position along the curve: 0 is the start, 1 the end. Default 0. |
Returns: construction plane.
przekroj = plane_along_path(sciezka, 0.5)Useful before a sweep: the profile is drawn on a plane perpendicular to the path.
plane_at_angle
A construction plane containing a sketch line, rotated about it by the given angle.
| parameter | type | description |
|---|---|---|
line (required) |
sketch entity | The sketch line the plane rotates about. |
angle (required) |
number | Angle in degrees, measured from the sketch plane. |
Returns: construction plane.
skos = plane_at_angle(krawedz, 30)Measurement
measure
Properties of a body: volume, area, centre of mass, extents.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body. |
Returns: record with fields volume, area, center, min, max, size.
m = measure(b)
print("objętość " + round(m.volume / 1000, 2) + " cm3")Document
color
Sets the colour of a body.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body. |
value (required) |
text | Colour in hexadecimal, for example "#c0392b". |
Returns: the same body.
color(b, "#3498db")hide
Hides a body, a sketch or a plane.
| parameter | type | description |
|---|---|---|
target (required) |
any | A body, a sketch or a plane. |
Returns: nothing.
material
Assigns a material from the appearance library to a body. A material with a density lets the mass be computed.
| parameter | type | description |
|---|---|---|
body (required) |
body | Body. |
value (required) |
text | Material name, for example "Aluminium". |
Returns: the same body.
name
Names a body or a sketch. The same name lets you find the object later through body("...").
| parameter | type | description |
|---|---|---|
target (required) |
any | A body or a sketch. |
label (required) |
text | New name. |
Returns: the same object.
name(b, "Korpus")remove
Removes a body, a sketch or a feature from the history.
| parameter | type | description |
|---|---|---|
target (required) |
any | Object to remove. |
Returns: nothing.
Removing a feature also removes everything that follows from it.
show
Shows a hidden body, sketch or plane.
| parameter | type | description |
|---|---|---|
target (required) |
any | A body, a sketch or a plane. |
Returns: nothing.
Exchange
export_file
Saves bodies to a file in the given format.
| parameter | type | description |
|---|---|---|
bodies (required) |
body or list of bodies | A body or a list of bodies. |
file (required) |
text | File name together with its extension. |
format |
text | Output format. Without it, taken from the file extension. Values: "step", "iges", "brep", "stl", "obj", "ply", "3mf", "glb", "dxf". |
Returns: nothing.
export_file(b, "korpus.step")import_file
Reads a CAD file and inserts its contents as bodies.
| parameter | type | description |
|---|---|---|
file (required) |
text | Name of the file to read. |
Returns: body or list of bodies.
The file has to be reachable for the application: in the browser, from the folder set in the model library settings.
View
fit
Fits the view so that the whole model is visible.
Returns: nothing.
section
Turns on section analysis: the model is shown cut by the given plane. Does not change the geometry.
| parameter | type | description |
|---|---|---|
plane (required) |
plane | Cutting plane. |
flip |
true/false | Show the other side. Default false. |
Returns: nothing.
section(plane.yz)section_off
Turns section analysis off.
Returns: nothing.
view
Sets the camera to a standard view.
| parameter | type | description |
|---|---|---|
name |
text | View name (a face, a corner or isometric). Values: "home", "top", "bottom", "front", "back", "left", "right", "iso", "top-front-left", "top-front-right", "top-back-left", "top-back-right", "bottom-front-left", "bottom-front-right", "bottom-back-left", "bottom-back-right". Default home. |
Returns: nothing.
Math
abs
Absolute value.
| parameter | type | description |
|---|---|---|
x (required) |
number | Number. |
Returns: number.
acos
Arccosine, result in degrees.
| parameter | type | description |
|---|---|---|
x (required) |
number | Number. |
Returns: number.
asin
Arcsine, result in degrees.
| parameter | type | description |
|---|---|---|
x (required) |
number | Number. |
Returns: number.
atan
Arctangent, result in degrees.
| parameter | type | description |
|---|---|---|
x (required) |
number | Number. |
Returns: number.
atan2
Angle in degrees of the vector (x, y) measured from the X axis.
| parameter | type | description |
|---|---|---|
y (required) |
number | Y component. |
x (required) |
number | X component. |
Returns: number: angle in degrees.
ceil
Rounds up.
| parameter | type | description |
|---|---|---|
x (required) |
number | Number. |
Returns: number.
clamp
A value clipped to a range.
| parameter | type | description |
|---|---|---|
x (required) |
number | Value. |
low (required) |
number | Lower bound. |
high (required) |
number | Upper bound. |
Returns: number.
cos
Cosine of an angle given in degrees.
| parameter | type | description |
|---|---|---|
x (required) |
number | Angle in degrees. |
Returns: number.
cross
Cross product: a vector perpendicular to both given ones.
| parameter | type | description |
|---|---|---|
a (required) |
[x, y, z] | First vector. |
b (required) |
[x, y, z] | Second vector. |
Returns: vector.
deg
Converts radians to degrees.
| parameter | type | description |
|---|---|---|
x (required) |
number | Angle in radians. |
Returns: number: angle in degrees.
dot
Dot product of two vectors.
| parameter | type | description |
|---|---|---|
a (required) |
[x, y, z] | First vector. |
b (required) |
[x, y, z] | Second vector. |
Returns: number.
floor
Rounds down.
| parameter | type | description |
|---|---|---|
x (required) |
number | Number. |
Returns: number.
length_of
Length of a vector.
| parameter | type | description |
|---|---|---|
v (required) |
[x, y, z] | Vector. |
Returns: number.
max
The larger of two numbers.
| parameter | type | description |
|---|---|---|
a (required) |
number | First number. |
b (required) |
number | Second number. |
Returns: number.
min
The smaller of two numbers.
| parameter | type | description |
|---|---|---|
a (required) |
number | First number. |
b (required) |
number | Second number. |
Returns: number.
normalized
A vector of length one pointing the same way as the given one.
| parameter | type | description |
|---|---|---|
v (required) |
[x, y, z] | Vector. |
Returns: vector.
pow
Power. The same as the ^ operator.
| parameter | type | description |
|---|---|---|
x (required) |
number | Base. |
y (required) |
number | Exponent. |
Returns: number.
rad
Converts degrees to radians. Rarely needed, because the whole language works in degrees.
| parameter | type | description |
|---|---|---|
x (required) |
number | Angle in degrees. |
Returns: number: angle in radians.
round
Rounds to the given number of decimal places.
| parameter | type | description |
|---|---|---|
x (required) |
number | Number. |
digits |
number | Number of decimal places. Default 0. |
Returns: number.
sin
Sine of an angle given in degrees.
| parameter | type | description |
|---|---|---|
x (required) |
number | Angle in degrees. |
Returns: number.
sqrt
Square root.
| parameter | type | description |
|---|---|---|
x (required) |
number | Number. |
Returns: number.
tan
Tangent of an angle given in degrees.
| parameter | type | description |
|---|---|---|
x (required) |
number | Angle in degrees. |
Returns: number.
vec
A vector or a point in space. The same as writing [x, y, z], handy when computing.
| parameter | type | description |
|---|---|---|
x (required) |
number | X component. |
y (required) |
number | Y component. |
z |
number | Z component. Default 0. |
Returns: vector [x, y, z].
Lists
count
Number of items in a list or in a set of edges or faces.
| parameter | type | description |
|---|---|---|
value (required) |
any | A list or a set. |
Returns: number.
item
An item of a list by index, counting from zero. A negative index counts from the end.
| parameter | type | description |
|---|---|---|
list (required) |
any | A list or a set. |
index (required) |
number | Item index. |
Returns: item.
range
A list of numbers from start to end, without the end value. For loops.
| parameter | type | description |
|---|---|---|
start (required) |
number | First value. |
end |
number | End value, not part of the list. |
step |
number | Step. Default 1. |
Returns: list of numbers.
for i in range(0, 5) { print(i) }
range(0, 100, 25)Diagnostics
assert
Stops the script when the condition does not hold. For checking assumptions, such as whether a selector matched as many edges as it should.
| parameter | type | description |
|---|---|---|
condition (required) |
any | The condition. |
message |
text | Error message. Default Warunek nie jest spełniony. |
Returns: nothing.
assert(edges(b, kind: "circle").count == 4, "spodziewam się czterech otworów")print
Prints a value in the script console.
| parameter | type | description |
|---|---|---|
value (required) |
any | What to print. |
Returns: nothing.
print("wysokość: " + h)