Class: Path

PD.CAD. Path

A utility class for creating a 2D path which may contain line, arc, bezier, spline and fillet segments.

This class is also exposed as just CAD.Path within the built-in code editor panel of each framework application that uses it.

After adding one or more segments, the path can be retrieved as either a oc.TopoDS_Wire or a oc.TopoDS_Face for subsequent use with other geometry operations.


new Path( [point])

Creates a new 2D path starting at the optional [x,y] point (or [0,0] by default) and containing one or more line, arc, bezier, bspline and.or fillet segments.

Parameters:
Name Type Argument Description
point Array.<number> <optional>

An [x,y] vector array defining the start position, defaults to origin.

Author:
  • drajmarsh
Example
const path = new PD.CAD.Path()
     .moveTo([ 0, -1000 ])
     .lineTo([ 0,     0 ])
     .fillet(500)
     .lineTo([ 1000, 0 ])
     .arcTo([ 1500, 500 ], [ 1000, 1000 ])
     .bezierTo([ [ 0, 1000 ], [ 0, 2000 ] ])
     .bsplineTo([ [ 0, 3000 ], [ -500, 3500 ], [ -1000, 3000 ], [ -1500, 3500 ], [ -2000, 3000 ] ])
     .end(true, false);

const face = path.asFace();
const wire = path.asWire();

Methods


addCircle(center, radius [, reversed])

Adds a closed circle to the current path.

This method can be used to punch a circular hole in the existing face if it lies entirely within a bounding path segment. You may need to set the reversed argument to ensure the correct orientation.

Parameters:
Name Type Argument Description
center Array.<number>

An [x,y,z] vector array defining the center point of the circle.

radius number

The circle radius in model units.

reversed boolean <optional>

Whether or not to reverse the vertex order the face, defaults to false.

Returns:

Returns this path instance to support method chaining.

Type
PD.CAD.Path

addWire(wire)

Adds a new wire to the current path.

Parameters:
Name Type Description
wire oc.TopoDS_Wire

The wire to add.

Returns:

Returns this path instance to support method chaining.

Type
PD.CAD.Path

arcTo(through, point)

Adds an arc segment from the previous point, through the given [x,y] point on the arc, to the given [x,y] point.

Parameters:
Name Type Description
through Array.<number>

An [x,y,z] vector array defining a point lying somewhere on the arc.

point Array.<number>

An [x,y,z] vector array defining the end of the arc segment.

Returns:

Returns this path instance to support method chaining.

Type
PD.CAD.Path

asFace( [reverse])

Converts the current path to a face and adds it to the CAD model.

Parameters:
Name Type Argument Description
reverse boolean <optional>

Whether or not to reverse the vertex order, defaults to false..

Returns:

Returns the current sketch as a face.

Type
oc.TopoDS_Face

asWire( [reverse])

Converts the current path to a wire and adds it to the CAD model.

Parameters:
Name Type Argument Description
reverse boolean <optional>

Whether or not to reverse the vertex order, defaults to false..

Returns:

Returns the current sketch as a wire.

Type
oc.TopoDS_Wire

bezierTo(controlPoints)

Adds an bezier curve from the previous point through the [x,y] control points.

This constructs an order-N Bezier Curve where the first N-1 points are control points and the last point is the end point of the curve.

Parameters:
Name Type Description
controlPoints Array.<Array.<number>>

An array of [x,y,z] vector arrays defining curve control points.

Returns:

Returns this path instance to support method chaining.

Type
PD.CAD.Path

bsplineTo(controlPoints)

Adds a BSpline from the previous point through the set of [x,y] control points.

Parameters:
Name Type Description
controlPoints Array.<Array.<number>>

An array of [x,y,z] vector arrays defining curve control points.

Returns:

Returns this path instance to support method chaining.

Type
PD.CAD.Path

close( [reverse])

Completes the current part of the path as a closed loop.

Parameters:
Name Type Argument Description
reverse boolean <optional>

Whether or not to reverse the vertex order, defaults to false..

Returns:

Returns this path instance to support method chaining.

Type
PD.CAD.Path

end( [close] [, reverse])

Completes the path and generates the internal representation.

Parameters:
Name Type Argument Description
close boolean <optional>

Whether or not to close the current shape, defaults to false.

reverse boolean <optional>

Whether or not to reverse the vertex order, defaults to false..

Returns:

Returns this path instance to support method chaining.

Type
PD.CAD.Path

fillet(radius)

Adds a fillet with the given radius between the current and next segment.

Parameters:
Name Type Description
radius number

The fillet radius in model units.

Returns:

Returns this path instance to support method chaining.

Type
PD.CAD.Path

lineTo(point)

Adds a line segment from the previous point to the given [x,y] point.

Parameters:
Name Type Description
point Array.<number>

An [x,y,z] vector array defining the end of the segment.

Returns:

Returns this path instance to support method chaining.

Type
PD.CAD.Path

moveTo(point)

Begins a new path or a new part of an existing path at the given [x,y] point.

Parameters:
Name Type Description
point Array.<number>

An [x,y] vector array defining the start position.

Returns:

Returns this path instance to support method chaining.

Type
PD.CAD.Path