Getting Started

First Example

Let’s start with a simple box:

result = cadscript.make_box(40, 30, 4)

Now we fillet the corners. We choose the edges with the first argument for Body.fillet() method. "|Z" selects all edges parallel to Z axis. The second argument is the radius of the fillet.

result = cadscript.make_box(40, 30, 4)
result.fillet("|Z", 5)

Next we add a little chamfer to the top and bottom edges. Again, the first argument selects the edges to work on. "#Z" selects all edges perpendicular to Z axis, that is, parallel to the XY plane.

result = cadscript.make_box(40, 30, 4)
result.fillet("|Z", 5)
result.chamfer("#Z", 0.8)

We continue by creating a sketch and drawing a heart. We start with a square.

sketch = cadscript.make_sketch()
sketch.add_rect(12, 12)

Then we add two circles at the center of two of the sides. The operation is a Boolean union, so the circles are merged with the square.

sketch = cadscript.make_sketch()
sketch.add_rect(12, 12)
sketch.add_circle(diameter=12, positions=[(6, 0), (0, 6)])

Finally, we place the sketch on the top face of our object, rotate it 45 degrees, and use it to cut a hole by extruding it down (negative value).

result = cadscript.make_box(40, 30, 4)
result.fillet("|Z", 5)
result.chamfer("#Z", 0.8)

sketch = cadscript.make_sketch()
sketch.add_rect(12, 12)
sketch.add_circle(diameter=12, positions=[(6, 0), (0, 6)])

result.cut_extrude(">Z", sketch.rotate(45), -4)



Second Example

In this example we build a complex object by

  • creating two sketches

  • extruding them

  • intersecting the two extrusions

Let’s start with the first sketch. We add a rectangle with width 70 and height 30, centered at the origin.

sketch1 = cadscript.make_sketch()
sketch1.add_rect(70, 30)

Now we add chamfers. “>X” selects all vertices with maximum X coordinate. This will add a chamfer at the corners at the right side of the rectangle. The chamfer will be symmetric, with a distance of 10mm.

...
sketch1.chamfer(">X", 10)

We add another rectangle, this time with width 50 and height 20. This time, the centering is done along the Y axis only. The new rectangle will be “added”, that is, it will be unioned with the first rectangle. After that we add a circle with diameter 30, its center at x=50,y=0.

...
sketch1.add_rect(50, 20, center="Y")
sketch1.add_circle(d=30, pos=(50, 0))

Now we cut a rectangle from the sketch. The dimension in x direction is here given by a tuple. The first value is the start position, the second value is the end position. In y direction, the dimension is 16mm. It will be centered, so it will range from -8 to +8 in y direction.

...
sketch1.cut_rect((-50, 20), 16, center="Y")

Now we do a couple of fillets. “<X” selects all vertices with minimum X coordinate. You can invert that by using “not <X”, which selects all vertices but the ones with minimum X coordinate.

...
sketch1.fillet("not <X", 4)

Cutting a circle from the sketch, centered at x=50, y=0 with diameter 16.

...
sketch1.cut_circle(d=16, pos=(50, 0))

now we create the second sketch. We start with a rectangle and a circle.

sketch2 = cadscript.make_sketch()
sketch2.add_rect(70, 5, center=False)
sketch2.add_circle(d=26, pos=(0, 10))

We add a fillet now. We want only the point where the circle and the rectangle meet at a sharp angle. The search string “>>X” sorts all points (also called vertices) in positive X direction. The “[1]” selects the second point in that list (first in the list has index 0), which is the one we want. “>>X[0]” would select the point where the circle and the rectangle meet at the bottom. “>>X[2]” returns the corners of the rectangle at the right side. Here two points are selected, because they both have the same X coordinate.

...
sketch2.fillet(">>X[1]", 15)

Now we cut a circle and a rectangle from the sketch The circle is centered at x=0,y=10 with diameter 12. The rectangle ranges from -50 to 50 in x direction and -100 to 0 in y direction, effectively cutting off the lower half of the sketch.

...
sketch2.cut_circle(d=12, pos=(0, 10))
sketch2.cut_rect(100, (-100, 0), center="X")

Now we place the first sketch on the XY plane and make an extrusion. The extrusion will happen perpendicular to the plane, that is, in positive Z direction.

extr1 = cadscript.make_extrude("XY", sketch1, 30)

Now we do the same for the second sketch. We use the XZ plane this time, so the extrusion will happen in Y direction. The extrusion amount is given as a tuple, the first value is the start position, the second value is the end position.

extr2 = cadscript.make_extrude("XZ", sketch2, (-20, 20))

Finally, we intersect the two extrusions. This performs a boolean intersection of the two bodies.

...
result = extr2.intersect(extr1)

The complete script looks like this:

sketch1 = cadscript.make_sketch()
sketch1.add_rect(70, 30)
sketch1.chamfer(">X", 10)
sketch1.add_rect(50, 20, center="Y")
sketch1.add_circle(d=30, pos=(50, 0))
sketch1.cut_rect((-50, 20), 16, center="Y")
sketch1.fillet("not <X", 4)
sketch1.cut_circle(d=16, pos=(50, 0))

sketch2 = cadscript.make_sketch()
sketch2.add_rect(70, 5, center=False)
sketch2.add_circle(d=26, pos=(0, 10))
sketch2.fillet(">>X[1]", 15)
sketch2.cut_circle(d=12, pos=(0, 10))
sketch2.cut_rect(100, (-100, 0), center="X")

extr1 = cadscript.make_extrude("XY", sketch1, 30)
extr2 = cadscript.make_extrude("XZ", sketch2, (-20, 20))

result = extr2.intersect(extr1)