Scripted CAD modeling with an AI assistant
In Foremka you can build a model with a short program as well as with the mouse. A script calls the same operations as the ribbon, so each one lands on the timeline as an ordinary history step that you can change later, just like one you clicked. That helps with parts that differ only in size, with repeated holes, and whenever a shape is easier to describe with numbers than to draw. Next to the console sits an assistant that writes such scripts from a plain description.
What a script looks like
The Console button on the UTILITIES tab opens the console, and Ctrl+Enter runs the script. This example makes a 120 by 80 mm plate with rounded corners and four holes:
# A 120 x 80 mm base plate with four holes
thickness = param("thickness", 8)
outline = sketch(plane.xy) {
rect(center: [0, 0], width: 120, height: 80)
}
b = extrude(outline, thickness)
b = fillet(edges(b, dir: up), 8)
for i in range(0, 4) {
b = hole(face(b, "top"), at: [-45 + i * 30, 0], diameter: 5)
}
name(b, "Base plate")param stores the thickness as a project parameter. It shows up in the Parameters panel, and when you change the value the whole model rebuilds itself. Edges are picked by description rather than by number: edges(b, dir: up) means the vertical edges, so the selection survives a change of dimensions. Numbers may carry units, such as 12mm, 1in or 30deg.
What the language covers
- variables, conditions, loops and your own functions;
- over 140 functions: constrained sketches, text in any bundled font (at a point, in a frame or along a curve), primitives and gears, extrude, revolve, sweep, loft, fillets, chamfers, shells, threaded holes, booleans, repeating features in rows and around a circle, surfaces, measurements, materials and export to files (STEP, STL, 3MF and more);
- completion of names and arguments in the editor, a description of the function under the cursor, and errors pointed out by line number;
- Save model as script: the model, including what you built with the mouse, turns into a script you can save to a file and run in another project (whatever the language cannot express, such as mesh bodies, is noted in a comment);
- CadQuery scripts: the console recognizes them on its own and runs them with its own interpreter, so they leave a full history in the tree as well.
text()takes a font by name (font="Arial"gives a font with the same character widths) or from a file (fontPath), and the lettering stays in the sketch as text you can fix with a double-click.
The complete syntax and every function are described in the scripting language documentation.
The assistant
The second tab of the console is the Assistant. Describe in plain words what you want, for example “a 40x40x20 block with an 8 mm through hole”, and attach a drawing, a photo or a PDF as a reference if you have one. The assistant writes a CadQuery script and runs it in the open project. Then it looks at the model from six directions, checks the dimensions and fixes what went wrong, with at most five attempts per question. It cleans up its failed attempts.
Everything it builds sits in the project history, so you change or delete it like your own work, and you can expand the script of every attempt and read it. The assistant only deals with the part being built and does not answer questions unrelated to the model. It works when you are signed in: every account gets a free monthly allowance, and a counter in the application bar shows how much of it is left.
Things to keep in mind
- A script appends operations to the end of the history, so running it twice builds the model twice. Remove extra steps from the timeline or the tree.
- In scripts the vertical axis is Y:
plane.xylies flat andbox([80, 20, 40])is 20 mm tall. - The language covers part modeling. Assemblies, sculpting, meshes and nesting are done with the mouse.
- Not every CadQuery script runs unchanged, because Foremka supports the commonly used commands rather than the whole of Python.