FoundationCheatsheet

Foundation Cheatsheet

Starting components/assemblies.

from cadbuildr.foundation.utils import Part, Assembly
Part() -> Part
Assembly() -> Assembly

Planes

from cadbuildr.foundation.plane import Plane
(Part|Asssembly).xy() -> Plane
(Part|Asssembly).yz() -> Plane
(Part|Asssembly).xz() -> Plane
# makes a new plane parallel to the current plane at a distance (can be negative) on the normal vector
Plane.get_parallel_plane(self, distance: float, name: str) -> Plane
# makes a new plane at an angle from the current plane rotated around the specified axis
Plane.get_angle_plane_from_axis(self, axis: ndarray, angle: float, name: str) -> "Plane"

Sketches

from cadbuildr.foundation.sketch import Sketch
sketch = Sketch(plane: Plane)

Sketch Elements

Point(sketch: Sketch, x: float, y: float) -> Point
Line(p1: Point, p2: Point) -> Line
# You can access the points of the line using Line.p1 and Line.p2
Axis(line: Line) -> Axis
# Access `Axis.line`, useful for lathe operations

Sketch Shapes

ClosedSketchShapeTypes = Polygon | Circle | Ellipse
Polygon(lines: List[Line]) -> Polygon
# You can access the lines of the polygon using Polygon.lines
Circle(center: Point, radius: float) -> Circle
#You can access the center of the circle using `Circle.center` and the radius using `Circle.radius`
Ellipse(center: Point, a: float, b: float) -> Ellipse`
# Access `Ellipse.center`, `Ellipse.a`, `Ellipse.b`
# Some Polygon shortcuts :
Rectangle.from_center_and_sides(center: Point, length: float, width: float) -> Polygon
Rectangle.from_2_points(p1: Point, p2: Point) -> Polygon
Square.from_center_and_side(center: Point, side: float) -> Polygon

Sketch Pencil

from cadbuildr.foundation.sketch import Sketch `sketch = Sketch(plane: Plane) sketch.pencil.move(x, y)‘

Movement

move(dx: float, dy: float):: relative movement move_to(x: float, y: float): absolute movement

Drawing

line(dx: float, dy: float) line_to(x: float, y: float) arc(dx: float, dy: float, radius: float) arc_to(x: float, y: float, radius: float) tangent_arc(dx: float, dy: float) tangent_arc_to(x: float, y: float) rounded_corner_then_line(dx: float, dy: float, radius: float) rounded_corner_then_line_to(x: float, y: float, radius: float)

Shape Completion

get_closed_shape() -> CustomClosedShape close_with_mirror() -> CustomClosedShape

Operations

from cadbuildr.foundation.operations import Lathe, Extrusion, Hole
#to add an operation to a component
Part.add_operation(operation: Operation) -> None
 
Lathe(shape: ClosedSketchShapeTypes, axis: Axis, cut: bool = False) -> Lathe
Extrusion(shape: ClosedSketchShapeTypes, end: float, start: float = 0, cut: bool = False) -> Extrusion
# Shortcut for an extrusion with a circle shape
Hole(point: Point, radius: float, depth: float) -> Hole

Assembly/Part

assy = Assembly()
assy.add_component(component: Part|Assembly, tf: TransformMatrix | None = None) -> None
# adds a component to the assembly. You can use the `TFHelper` for the transform matrix. Only Assemblies can do `add_component`
#You can also directly use methods on the Part or Assembly object to move it.
(Part|Assembly).translate(translation: ndarray) -> None`
(Part|Assembly).translate_x(distance: float) -> None`
# Same with y and z
(Part|Assembly).rotate(axis: ndarray, angle: float) -> None`
# axis is the rotation axis, angle is the rotation angle in radians

Applying a Material

Material() -> Material
Material.set_diffuse_colorRGB(r: int, g: int, b: int) -> None
Material.set_transparency(alpha: float) -> None
# alpha is the transparency value (0-1)
# You can then apply a material to a component by doing
Part.set_material(material: Material)
# You can also directly paint a component by doing
Part.paint(color_name: str)

TFHelper

from cadbuildr.foundation import TFHelper
TFHelper() -> TFHelper
TFHelper.get_tf() -> TransformMatrix
TFHelper.set_tf(tf: TransformMatrix) -> None
TFHelper.translate(translation: ndarray) -> None
TFHelper.translate_x(distance: float) -> None
# Same with y and z
TFHelper.rotate(axis: ndarray, angle: float) -> None
# axis is the rotation axis, angle is the rotation angle in radians

Good practice :

For Part we recommend making a class inheritating from the Part class for which the constructor calls methods for the different operations/sketches.

Similarly for Assembly we recommend making a class inheritating from the Assembly class for which the constructor calls methods for the different components/subassemblies making that assembly