Digital Handstand
← Back to FlywheelCAD
Reference
FlywheelCAD icon

Python Syntax

Public command reference for the FlywheelCAD Python API.

A FlywheelCAD document is ordinary Python. The app runs that Python through the bundled flywheelcad module, which emits CAD commands that are then parsed and replayed by the app.

from flywheelcad import *
cad = FlyWheelCAD()

Setup and Helpers

FlyWheelCAD() Creates or returns the shared API object. Multiple calls return the same singleton, which keeps variable naming and origin references consistent across helper modules.
cad.with_sketch(plane_name) Switches the active sketch context to a plane such as "xy", "yz", "zx", or a custom plane name.
cad.origin(plane_name) Returns the origin ref for a sketch plane. Standard origins such as origin_xy are auto-injected; custom origins appear as origin_<plane_name> once a plane is used.
ref(name) Creates a symbolic reference by name. Useful when a valid CAD symbol exists but is not bound as a Python variable in the current scope.
region(required, optional=None, witness=None, adjacent=None, side=None) Builds a region intent for body commands. required is the main boundary; the optional arguments help the matcher pick the intended closed area.
cw(ref) / ccw(ref) Annotates boundary orientation when you need to force clockwise or counter-clockwise interpretation inside a region definition.

Geometry Creation

cad.point2d(x, y) Creates a 2D point in the active sketch plane and returns a point ref.
cad.line2d(p1, p2, construction=False) Creates a line between two point refs. Set construction=True for guide geometry.
cad.circle2d(center, radius, construction=False) Creates a circle from a center point ref and numeric or variable radius.
cad.ellipse2d(focus1, focus2, point, construction=False) Creates an ellipse from two foci and one boundary point.
cad.spline2d(points, closed=False, construction=False) Creates a spline through a list of point refs. Set closed=True for a closed spline.
cad.arc2d(center, start, end, clockwise=False, construction=False) Creates an arc from center, start, and end points. Use clockwise=True when needed.
cad.trim(element, near) Trims an element near a supplied (x, y) location. Returns the surviving element ref and a secondary split ref when trim produces two pieces.

Geometric Constraints

cad.horizontal(line)Makes a line horizontal in the current sketch plane.
cad.vertical(line)Makes a line vertical in the current sketch plane.
cad.parallel(line1, line2)Constrains two lines to remain parallel.
cad.perpendicular(line1, line2)Constrains two lines to be perpendicular.
cad.collinear(line1, line2)Places two lines on the same infinite line.
cad.coincident(p0, p1)Makes two points share the same location.
cad.pointlinecoincident(point, line)Places a point onto a line.
cad.pointoncircle(point, circle)Constrains a point to lie on a circle.
cad.pointonellipse(point, ellipse)Constrains a point to lie on an ellipse.
cad.pointonplane(point, plane)Constrains a point reference onto a plane object.
cad.concentric(circle1, circle2)Makes two circles share a center.
cad.equallines(line1, line2)Makes two line lengths equal.
cad.equalradius(circle1, circle2)Makes two circle radii equal.
cad.circletangentline(circle, line)Makes a circle tangent to a line.
cad.circletangentcircle(circle1, circle2)Makes two circles tangent to each other.
cad.ellipsetangentline(ellipse, line)Makes an ellipse tangent to a line.
cad.splinetangentline(spline, line)Makes a spline tangent to a line.
cad.symmetryline(...)Advanced symmetry constraint around a sketch line. Use keyword arguments such as point refs and the symmetry line ref.
cad.symmetryplane(...)Advanced symmetry constraint around a plane, used through keyword arguments.

Dimensions and Variables

cad.variable(value=None, fixed=False) Creates a scalar variable ref such as d1. Use it in dimensions directly or inside arithmetic expressions.
cad.distance(p0, p1, distance)Sets the distance between two points. Keyword or positional form is supported.
cad.length(line, length)Sets a line length.
cad.radius(circle, radius)Sets a circle radius.
cad.angle(line1, line2, angle=None)Constrains the angle between two lines. If the angle is omitted, the app records the relation without a fixed value.
cad.pointlinedistance(point, line, distance)Sets the perpendicular distance from a point to a line.
cad.fraction(...)Advanced fractional constraint helper. Pass keyword arguments only.
width = cad.variable(80, fixed=True)
clearance = cad.variable(12)
cad.length(line, width * 2 + clearance)

Updates and Editing Helpers

cad.merge_points(source, target)Merges two points so they become one shared point in the model.
cad.mirror(elements, symmetry_line)Mirrors a list of elements across a symmetry line.
cad.update(changes)Updates existing geometry properties, usually point coordinates such as {p1: {"x": 10, "y": 20}}.
cad.ensure_convergence()Forces an explicit sketch solve when a script wants to converge before continuing.
cad.label_offset(key, dx, dy)Adjusts a dimension or annotation label offset by key.

Bodies, Analysis, and Custom Planes

cad.extrude(plane, region, distance, direction=None, quality=None)Creates a solid by extruding a region on a given plane. Returns a body ref.
cad.revolve(plane, region, axis, angle, quality=None)Creates a revolved body from a region and selected axis line.
cad.loft(start_plane, start_region, end_plane, end_region, quality=None)Creates a lofted body between two regions on different planes.
cad.bool_union(*bodies, quality=None)Creates the boolean union of two or more bodies.
cad.bool_difference(*bodies, quality=None)Subtracts later bodies from the first body.
cad.bool_intersection(*bodies, quality=None)Keeps only the shared volume between bodies.
cad.section(body, plane)Creates a section curve of a body on a target plane.
cad.project(body, plane)Projects body silhouette-style geometry onto a target plane.
cad.project_point(point, plane)Projects a topology point onto another plane.
cad.create_sketch_plane(p1, p2, p3, name=None)Creates a named custom sketch plane from three 3D points or topology refs.
Body refs: body-producing commands return refs that expose topology points such as body1.v0, body1.v1, or similar names. Those are what you pass into create_sketch_plane(...), project_point(...), or helper functions that need body topology.

Including a Separate Python File

Put the helper module next to the main script you open in FlywheelCAD. The app executes the document using that folder as the working directory, so sibling imports work directly.

MyProject/
  gearbox.py
  CADgears.py
  CADpolygons.py
from flywheelcad import *
from CADgears import gear_outline
from CADpolygons import regular_polygon

cad = FlyWheelCAD()

cad.with_sketch("xy")
regular_polygon(center_x=0, center_y=0, side_count=6, radius=80, plane_name="xy")
gear = gear_outline(center_x=180, center_y=0, tooth_count=18, module=5.0, plane_name="xy")
gear_body = cad.extrude("xy", gear["region_ring"], 24, quality="high")

This is the same pattern used by the included test projects, especially the gear examples.