Python API

Everything the UI does, a script can do. This list is generated from the application's command catalog, so it is the same list the command palette uses.

Import yonta from the Python console inside the application or from a standalone script. Every command is one undo step and is recorded by the macro recorder as the Python call shown here.

A parameter marked ? is optional. Methods on Document and Sketch are called on an object, so their document parameter is implied. The same list as JSON: commands.json.

A complete example

import yonta

doc = yonta.new_document("Bracket")
sketch = doc.new_sketch(plane="XY", name="Body")
sketch.add_circle((0, 0), 20.0)
body = doc.pad(sketch, 10.0)
doc.recompute()
doc.export("bracket.step")
doc.save("bracket.yonta")

Application

yonta.new_document(name?)

Command: app.new_document · New Document

Create a new document and make it active.

Example

doc = yonta.new_document("Bracket")

yonta.open_document(path, name?, background?)

Command: app.open_document · Open Document

Open a .yonta file as a new document.

Example

doc = yonta.open_document("bracket.yonta")

yonta.close_document(document?)

Command: app.close_document · Close Document

Close a document without saving.

Example

yonta.close_document(doc)

yonta.set_active_document(document)

Command: app.set_active_document · Switch Document

Make an open document the active one.

Example

yonta.set_active_document(doc)

Document

Document.add_object(document?, type, name?)

Command: doc.add_object · Add Object

Add an object of a registered type.

Example

sketch = doc.add_object("Sketcher::Sketch", "Body")

Document.remove_object(document?, object)

Command: doc.remove_object · Remove Object

Remove an object.

Example

doc.remove_object(body)

Document.set_property(document?, object, property, value)

Command: doc.set_property · Set Property

Set a property of an object.

Example

doc.set_property(body, "Length", 10.0)

Document.recompute(document?, background?)

Command: doc.recompute · Recompute

Recompute a document.

Example

doc.recompute()

Document.undo(document?)

Command: doc.undo · Undo

Undo the last change of a document.

Example

doc.undo()

Document.redo(document?)

Command: doc.redo · Redo

Redo the last undone change of a document.

Example

doc.redo()

Document.save(document?, path?, rename?)

Command: doc.save · Save

Save a document to a .yonta file.

Example

doc.save("bracket.yonta")

Document.export(document?, path, objects?)

Command: doc.export · Export

Export solids to STEP or STL.

Example

doc.export("bracket.step")

Document.import_step(document?, path, name?)

Command: doc.import_step · Import STEP

Import a STEP file as a solid.

Example

imported = doc.import_step("housing.step")

Part Design

Document.new_sketch(document?, plane?, support?, face?, name?)

Command: part.new_sketch · New Sketch

Add a sketch on a base plane or a planar face.

Example

sketch = doc.new_sketch(plane="XY", name="Body")

Document.pad(document?, profile, length?, name?)

Command: part.pad · Pad

Extrude a closed sketch into a solid, joined to the tip solid.

Example

body = doc.pad(sketch, 10.0)

Document.pocket(document?, profile, length?, name?, through_all?)

Command: part.pocket · Pocket

Cut a closed sketch into the tip solid.

Example

body = doc.pocket(sketch, 5.0)

Document.revolve(document?, profile, angle?, axis?, name?)

Command: part.revolve · Revolve

Revolve a closed sketch about an axis, joined to the tip solid.

Example

body = doc.revolve(sketch, 360.0)

Document.groove(document?, profile, angle?, axis?, name?)

Command: part.groove · Groove

Revolve a closed sketch about an axis and cut it from the tip solid.

Example

body = doc.groove(sketch, 90.0)

Document.fillet(document?, edges, radius?, base?, name?)

Command: part.fillet · Fillet

Round edges of the tip solid with a radius.

Example

body = doc.fillet([edge], 1.0)

Document.chamfer(document?, edges, size?, base?, name?)

Command: part.chamfer · Chamfer

Bevel edges of the tip solid by a distance.

Example

body = doc.chamfer([edge], 0.5)

Document.mirror(document?, plane?, support?, face?, base?, name?)

Command: part.mirror · Mirror

Join the tip solid with its reflection in a plane or a planar face.

Example

body = doc.mirror(plane="YZ")

Document.hole(document?, profile, diameter?, depth?, through_all?, base?, name?)

Command: part.hole · Hole

Drill plain holes at a sketch's points and circle centres into the tip solid.

Example

body = doc.hole(sketch, 3.0, 5.0)

Document.datum_plane(document?, plane?, support?, face?, offset?, name?)

Command: part.datum_plane · Datum Plane

A reference plane on a base plane or a planar face, moved by an offset.

Example

doc.datum_plane()

Document.datum_axis(document?, axis?, support?, edge?, offset?, name?)

Command: part.datum_axis · Datum Axis

A reference axis along X, Y or Z, or on a straight edge, moved by an offset.

Example

doc.datum_axis()

Document.datum_point(document?, support?, vertex?, offset?, name?)

Command: part.datum_point · Datum Point

A reference point at the origin or a vertex, moved by an offset.

Example

doc.datum_point()

Sketcher

Sketch.add_line(document?, sketch, kind, coords, construction?)

Command: sketch.add_geometry · Add Sketch Element

Add a point, line, circle or arc to a sketch.

Example

line = sketch.add_line((0, 0), (10, 0))

Sketch.copy(document?, sketch, geometry, offset?, angle?, center?)

Command: sketch.copy_geometry · Copy Sketch Elements

Copy sketch elements moved by an offset or turned about a point, with the constraints among them.

Example

copies = sketch.copy([line], offset=(10.0, 0.0))

Sketch.add_external(document?, sketch, object, edge)

Command: sketch.add_external · Add External Geometry

Project an edge of another object into the sketch as fixed construction geometry that follows it.

Example

sketch.add_external(body, edge)

Sketch.add_constraint(document?, sketch, type, first, second?, value?, value2?, third?)

Command: sketch.add_constraint · Constraint

Add a sketch constraint.

Example

sketch.add_constraint("coincident", (line, "end"), (other, "start"))

Sketch.set_value(document?, sketch, constraint, value)

Command: sketch.set_value · Change Dimension

Change a sketch dimension.

Example

sketch.set_value(constraint, 10.0)

Sketch.remove_geometry(document?, sketch, geometry)

Command: sketch.remove_geometry · Remove Sketch Element

Remove a sketch element and its constraints.

Example

sketch.remove_geometry(line)

Sketch.remove_constraint(document?, sketch, constraint)

Command: sketch.remove_constraint · Remove Constraint

Remove a sketch constraint.

Example

sketch.remove_constraint(constraint)