AlphaPrism is in active development: features may change and you may run into bugs. Keep backups of your work.Known issuesReport a bug
Skip to content

Python reference ​

cadkit is the Python library that ships with Prism. It needs only the standard library. Parameters are written in snake_case and matched to on-screen labels by partial text, so cad.box(width=40) sets Width and cad.flange(bend_radius=3) sets Bend radius (inside). Objects can be passed by name or as the Obj a call returned.

python
import cadkit as cad

Every function that makes something goes through run(), so anything missing here can still be reached with cad.run("command_name", ...). See the command reference for every command name.

Connection ​

CadError ​

python
class CadError

The application refused a request; the message is the one shown in the application.

connect ​

python
cad.connect(port=None, token=None)

Point cadkit at an application instance. Normally not needed: it finds the running one by itself.

call ​

python
cad.call(tool, **args)

Call any application tool by name (the same tools the MCP bridge offers) and return its result.

tools ​

python
cad.tools()

Return the application automation tools and their argument schemas.

Document ​

Obj ​

python
class Obj

An object in the document. Returned by every modeling call; pass it (or its name) to the next one.

MemberDescription
to_dict(self)Everything the application reported about this object (bounds, size, volume, faces ...).
json(self)
sizeProperty.
boundsProperty.
refresh(self)
rename(self, new_name)
delete(self)

objects ​

python
cad.objects()

Every object in the document.

get ​

python
cad.get(name)

Look up one object by name and return it as an Obj.

state ​

python
cad.state()

The full document state: objects, selection, active command, sketch, camera and status messages.

undo ​

python
cad.undo(count=1)

Undo the last count steps.

redo ​

python
cad.redo(count=1)

Redo the last count undone steps.

delete ​

python
cad.delete(*objs)

Delete the given objects (names or Obj).

select ​

python
cad.select(*objs)

Replace the selection with the given objects, faces or edges.

save ​

python
cad.save(path)

Save the document to path (.prism).

view ​

python
cad.view(name=None, fit=False)

Set the camera to a standard view ("front", "top", "iso" ...); fit=True zooms to everything.

screenshot ​

python
cad.screenshot(wait_ms=250)

Capture the application window (the application answers with the picture data).

history ​

python
with cad.history(label='Script'):

Group everything inside the block into one undo step: with cad.history("Make bracket"): ...

show ​

python
cad.show(*things)

Print objects or results as compact JSON: the most complete thing an agent can read back.

Dialogs ​

ask ​

python
cad.ask(title='Parameters', **defaults)

The quick way to ask for numbers and options. The kind of field follows the default you give: cad.ask("Plate", width=60, depth=40, name="Plate 1", rounded=True, material=["Steel", "Aluminum"]). Returns a dict of the answers (numbers keep int or float as given), or None if cancelled.

dialog ​

python
cad.dialog(title, fields)

Show a dialog and wait for OK. fields are dicts: {"key", "label", "type": "number|text|check|choice", "value", ...}. Returns {key: value} or None if the user cancelled.

Any command ​

run ​

python
cad.run(command, slots=None, preview=False, points=None, **params)

Run any modeling command: run("fillet", slots={"Edges": [...]}, radius=2). Returns the new Obj list.

commands ​

python
cad.commands(query='')

Names run() accepts, optionally those containing query.

describe ​

python
cad.describe(command)

The slots (what to select) and parameters (name, type, default, range, options) of a command, as JSON.

help ​

python
cad.help(query='')

Search the commands and the cadkit functions for query and print a short answer.

Find and check geometry ​

faces ​

python
cad.faces(obj, **filters)

Find faces by geometry instead of index: faces(b, type="Plane", facing=(0, 0, 1)). Returns the tool's JSON (indices are 1-based, ready for fillet/chamfer/shell/hole slots). See help("solid_find") for every filter.

edges ​

python
cad.edges(obj, **filters)

Find edges by geometry: edges(b, direction=(0, 0, 1), min_size=10). Same filters as faces().

check ​

python
cad.check(obj, other=None, **kw)

Verify a body (validity, volume, closed, thin walls ...), or measure between obj and other. Returns JSON.

Sketches ​

sketch ​

python
cad.sketch(plane='XY', offset=0)

Start a sketch on 'XY', 'XZ', 'YZ', a construction plane's name, or a face {"object": "Box 1", "face": 6}.

Primitives ​

box ​

python
cad.box(width=20, depth=20, height=20, **p)

Create a box and return it. Extra keyword arguments set other Box settings, such as position_x.

cylinder ​

python
cad.cylinder(radius=10, height=20, **p)

Create a cylinder and return it.

sphere ​

python
cad.sphere(radius=10, **p)

Create a sphere and return it.

cone ​

python
cad.cone(radius=10, height=20, **p)

Create a cone and return it.

torus ​

python
cad.torus(major_radius=20, minor_radius=5, **p)

Create a torus and return it.

Features ​

extrude ​

python
cad.extrude(profile, distance=20, extent=None, operation=None, **p)

Extrude a sketch or face. extent can be "Two sides", "Symmetric", "To object", "Through all" ...; operation "Cut" etc.

revolve ​

python
cad.revolve(profile, angle=360, axis='World Z', **p)

Revolve a sketch or face about an axis ("World Z" by default).

sweep ​

python
cad.sweep(profile, path, **p)

Sweep a profile along a path.

loft ​

python
cad.loft(sections, rails=None, **p)

Loft through ordered sections, optionally along guide rails.

fillet ​

python
cad.fillet(edges, radius=2)

edges as in {"object": "Box 1", "edge": 3} or a list of them (edge numbers start at 1).

chamfer ​

python
cad.chamfer(edges, distance=1.5)

Chamfer edges by distance. Edges are given like fillet().

shell ​

python
cad.shell(faces, thickness=2, **p)

Hollow a solid, removing faces, with the given wall thickness.

holes ​

python
cad.holes(target, points, diameter=6, depth=None, **params)

Drill holes at world coordinates. target is a body (holes enter from the top, along world Z, by default) or a face; points is a list of (x, y) or (x, y, z). Through all unless depth is given. Returns the body after the last hole. Other command parameters pass through, e.g. direction="World X", hole_type="Threaded (modeled)", metric_size="M6".

rib ​

python
cad.rib(sketch, thickness=2, height=10, **p)

Add a rib from a sketched line or open profile to the body it touches.

thicken ​

python
cad.thicken(surface, thickness=3, **p)

Give a surface a thickness to make a solid.

split_body ​

python
cad.split_body(body, tool)

Split a body with a plane, face, surface or another solid.

Combine and transform ​

union ​

python
cad.union(body, *tools)

Join tools into body.

subtract ​

python
cad.subtract(body, *tools)

Cut tools out of body.

intersect ​

python
cad.intersect(body, *tools)

Keep only where body and tools overlap.

move ​

python
cad.move(objs, x=0, y=0, z=0)

Move objects by x, y, z millimetres.

rotate ​

python
cad.rotate(objs, angle, axis='Z')

Rotate objects by angle degrees about a world axis.

scale ​

python
cad.scale(objs, factor)

Scale objects by factor.

mirror ​

python
cad.mirror(objs, plane='XY')

Mirror objects across a world plane ("XY", "XZ" or "YZ").

linear_pattern ​

python
cad.linear_pattern(objects, count=4, spacing=20, direction='X axis', count2=1, spacing2=20, direction2='Y axis', **p)

Copy objects along one or two directions. Directions are "X axis", "Y axis" or "Z axis". Returns the new objects.

circular_pattern ​

python
cad.circular_pattern(objects, count=6, angle=360, axis='Z axis', **p)

Copy objects around an axis through the world origin (axis_passes_through="Center of the objects" to use their centre). result="Join into a body" or "Cut from a body" fuses or cuts the copies instead of leaving new bodies.

Direct edits ​

push_pull ​

python
cad.push_pull(faces, distance=10)

Move planar faces along their normal: positive pulls out, negative pushes in.

move_face ​

python
cad.move_face(faces, x=0, y=0, z=0, tilt=0)

Move faces by x, y, z and optionally tilt them; the body follows.

delete_face ​

python
cad.delete_face(faces)

Remove faces (a hole, fillet or pocket) and heal the body.

Sheet metal, layouts and drawings ​

flange ​

python
cad.flange(profile, thickness=2, bend_radius=2, width=30, **p)

Bent sheet metal from a sketch of the cross-section (straight lines, sharp corners).

flat_pattern ​

python
cad.flat_pattern(body, k_factor=0.44)

Unfold a sheet metal body into its flat pattern.

flatten ​

python
cad.flatten(source, **params)

Create a persistent flat layout. Select it later with refold() to return.

refold ​

python
cad.refold(pattern, geometry=None, target=None, **params)

Refold a saved layout; optionally wrap curves, sheets or solids onto it.

wrap ​

python
cad.wrap(geometry, reference, target, **params)

Map geometry between a planar reference and a surface, or between curves.

U/V/normal scales and offsets, mirror_u, swap_uv, flip_normal, keep_input_geometry and curve_tolerance are accepted keyword arguments.

drawing ​

python
cad.drawing(path, **options)

Write an engineering drawing (.svg, .pdf or .dxf); see the drawing_export tool for the options.

image ​

python
cad.image(path, on='Front plane (XZ)', width=200, opacity=60, **p)

Put a picture on a plane as a reference. on is "Front plane (XZ)", "Top plane (XY)" or "Right plane (YZ)".

edit_image ​

python
cad.edit_image(img, **p)

Change a picture: opacity, width, turn, move_right, move_up, mirror_left_to_right ...

Freeform ​

form_box ​

python
cad.form_box(**params)

Create an editable subdivision box; accepts width, depth, height, faces_x/y/z.

form_cylinder ​

python
cad.form_cylinder(**params)

Create an editable cylinder cage; accepts radius, height, sides, rings, caps.

form_loft ​

python
cad.form_loft(sections, **params)

Loft an editable cage through ordered curve/sketch sections.

form_pipe ​

python
cad.form_pipe(path, **params)

Build an editable round tube along a curve/edge.

form_info ​

python
cad.form_info(obj, summary=False, only=None)

Read a cage and its topology diagnostics; component indices are zero-based.

form_op ​

python
cad.form_op(obj, op, **options)

Undoable cage edit: e.g. bridge, set_vertices, inset, crease, move or insert_loop.

form_to_nurbs ​

python
cad.form_to_nurbs(obj)

Convert a cage to NURBS in place; save the editable form first if needed.

Manufacturing ​

cam_setup ​

python
cad.cam_setup(body, name='Setup 1', **p)

Stock, work zero and default tool for machining a body: stock_allowance_xy, top_allowance, tool_diameter, cutting_feed ...

cnc_profile ​

python
cad.cnc_profile(outlines, depth=None, **p)

Cut along outlines. depth = total cutting depth; also tool_diameter, cutting_feed, depth_per_pass, cut="..."

cnc_pocket ​

python
cad.cnc_pocket(outlines, depth=None, **p)

Clear the inside of closed outlines to depth, leaving islands.

cnc_adaptive ​

python
cad.cnc_adaptive(outlines, depth=None, **p)

Pocket with even tool load (faster, deeper).

cnc_drill ​

python
cad.cnc_drill(holes, depth=None, **p)

Drill the picked holes to depth.

cnc_face ​

python
cad.cnc_face(depth=None, **p)

Face the stock top.

cnc_rough ​

python
cad.cnc_rough(model, depth=None, **p)

Layered 3D roughing of setup stock with a flat end mill and finishing allowance.

cnc_finish ​

python
cad.cnc_finish(model, depth=None, **p)

3D parallel finishing over a model (cutter="Ball nose" by default).

cnc_post ​

python
cad.cnc_post(machine='GRBL', save_to='', **p)

Write G-code for the toolpaths in the document. machine: "GRBL", "Mach3" or "LinuxCNC".

cnc_design_check ​

python
cad.cnc_design_check(model, **p)

Screen top-down access, reach and wall thickness.

cnc_stock_review ​

python
cad.cnc_stock_review(model, **p)

Sample visible milling paths in the active setup and program order.

fdm_check ​

python
cad.fdm_check(model, **p)

Screen a CAD body or mesh for bed fit, nozzle walls and overhangs.

resin_check ​

python
cad.resin_check(model, **p)

Sample resin cavities, potential cups, islands and thin features; sampling_size sets grid resolution.

python
cad.print_export(folder, name='part', format='3MF', open_in='Save only', **p)

Write the model for a slicer. format: "3MF", "STL", "OBJ" or "PLY"; open_in: "Bambu Studio", "OrcaSlicer", "PrusaSlicer" or "Save only". Same file name each time, so the slicer can reload from disk.

resin_export ​

python
cad.resin_export(folder, name='part', format='3MF', open_in='Save only', **p)

Export for an external resin slicer; supports/exposure are configured there.

Other ​

run_report ​

python
cad.run_report(command, slots=None, preview=False, points=None, **params)

Run a command with the same arguments as run(), returning the full command or preview report.

fold ​

python
cad.fold(sketch, thickness=2, bend_radius=2, angle=90, **p)

Fold a flat sketch into sheet metal and return the folded solid. The sketch holds the outline (normal lines, holes as loops) and each bend as a construction line across it. angle is in degrees. angle_of_each_bend="90, -90" and radius_of_each_bend="3, 80" set signed angles and inside radii bend by bend. The flat pattern is also made beside the part; pass also_make_the_flat_pattern_beside_the_part=False to skip it. fixed_region="The region over the sketch origin" holds that region still instead of the largest.

edge_flange ​

python
cad.edge_flange(face, length=20, angle=90, bend_radius=2, **p)

Add a flange along the edge of a sheet-metal body. face is the thin end face of the sheet as {"object": "Plate 1", "face": 3}. fold_toward="Down (the lower face)" folds the flange the other way.