Download this example

Download this example as a Jupyter Notebook or as a Python script.

PyAnsys Geometry 101: Sketching#

With PyAnsys Geometry, you can build powerful dynamic sketches without communicating with the Geometry service. This example shows how to build some simple sketches.

Perform required imports#

Perform the required imports.

from pint import Quantity

from ansys.geometry.core.math import Plane, Point2D, Point3D, Vector3D
from ansys.geometry.core.misc import UNITS
from ansys.geometry.core.sketch import Sketch

Add a box to sketch#

The Sketch object is the starting point. Once it is created, you can dynamically add various curves to the sketch. Here are some of the curves that are available:

  • arc

  • box

  • circle

  • ellipse

  • gear

  • polygon

  • segment

  • slot

  • trapezoid

  • triangle

Add a box to the sketch.

sketch = Sketch()

sketch.segment(Point2D([0,0]), Point2D([0,1]))
sketch.segment(Point2D([0,1]), Point2D([1,1]))
sketch.segment(Point2D([1,1]), Point2D([1,0]))
sketch.segment(Point2D([1,0]), Point2D([0,0]))


A functional-style sketching API is also implemented. It allows you to append curves to the sketch with the idea of never picking up your pen.

Use the functional-style sketching API to add a box.

sketch = Sketch()

    sketch.segment(Point2D([0,0]), Point2D([0,1]))


A Sketch object uses the XY plane by default. You can define your own custom plane using three parameters: origin, direction_x, and direction_y.

Add a box on a custom plane.

plane = Plane(origin=Point3D([0,0,0]), direction_x=Vector3D([1,2,-1]), direction_y=Vector3D([1,0,1]))

sketch = Sketch(plane)[0,0]), 1, 1)


Combine concepts to create powerful sketches#

Combine these simple concepts to create powerful sketches.

# Complex Fluent API Sketch - PCB

sketch = Sketch()

    sketch.segment(Point2D([0, 0],, Point2D([40, 1],, "LowerEdge")
      .arc_to_point(Point2D([41.5, 2.5],, Point2D([40, 2.5],, tag="SupportedCorner")
      .segment_to_point(Point2D([41.5, 5],
      .arc_to_point(Point2D([43, 6.5],, Point2D([43, 5],, True)
      .segment_to_point(Point2D([55, 6.5],
      .arc_to_point(Point2D([56.5, 8],, Point2D([55, 8],
      .segment_to_point(Point2D([56.5, 35],
      .arc_to_point(Point2D([55, 36.5],, Point2D([55, 35],
      .segment_to_point(Point2D([0, 36.5],
      .segment_to_point(Point2D([0, 0],
      .circle(Point2D([4, 4],, Quantity(1.5,, "Anchor1")
      .circle(Point2D([51, 34.5],, Quantity(1.5,, "Anchor2")