# Sketch (hwx.common)¶

Creates 2D parametric sketch geometry.

It is used to add items (points, lines, circles…) and constraints to them. Also contains sketch editing operations such as trim, fillet etc.

These APIs only work in GUI mode! Batch mode will be supported in a future release.

## Method Details¶

addArc3Points(self, start, end, third)

Adds an arc by defining three points.

param start: The start point of the arc. Union[Point, tuple[float, float]] The end point of the arc. Union[Point, tuple[float, float]] An another point of the arc. Union[Point, tuple[float, float]] The new arc. Circle
addArcCenter2Points(self, center, point1, point2, ccw=True)

Adds an Arc defined by its center and its endpoints.

param center: The center of the arc. Union[Point, tuple[float, float]] The point of the circle. Union[Point, tuple[float, float]] The point of the circle. Union[Point, tuple[float, float]] Determines whether to use counter clockwise direction from point1 to point2 or not. bool The new arc. Circle
addArcTangentTo(self, tangentTo, start, end, bInvertTangent=False)

Adds an arc, starting tangent to a curve on a start point and ending on a defined point.

param tangentTo:
The item to be tangent to.
type tangentTo:InterfaceItem
param start:The point where the arc starts.
type start:Point
param end:The end point of the arc.
type end:tuple[float, float]
param bInvertTangent:
Determines whether to construct the arc with inverted tangent.
type bInvertTangent:
bool
returns:The new arc.
rtype:Circle
addBoundedEllipse(self, center, majorAxisPoint, minorAxisPoint, start, end, bCounterClockWise=False)

Adds an ellipse defined by center, two points that define an axis and start and end points.

param center: type center: The center of the ellipse. tuple[float, float] The start point defining the major axis. tuple[float, float] The end point defining the major axis. tuple[float, float] The start point of the ellipse. tuple[float, float] The end point of the ellipse. tuple[float, float] Determines whether to use counter clockwise direction from start to end or not. bool The new ellipse. Ellipse
addCircle2Points(self, point1, point2)

Adds a circle defined by the 2 endpoints of a diameter.

param point1: The endpoint of the diameter. Union[Point, tuple[float, float]] The endpoint of the diameter. Point, tuple[float, float]float The new circle. Circle
addCircle3Points(self, point1, point2, point3)

Adds a circle defined by three points.

param point1: The point of the circle. Union[Point, tuple[float, float]] The point of the circle. Union[Point, tuple[float, float]] The point of the circle. Union[Point, tuple[float, float]] The new circle. Circle
addCircleCenterPoint(self, center, point)

Adds a circle defined by its center and one point.

param center: The center of the circle. Union[Point, tuple[float, float]] The point of the circle. Union[Point, tuple[float, float]] The new circle. Circle
addCircleCenterRadius(self, center, radius)

param center: The center of the circle. Union[Point, tuple[float, float]] The radius of the circle. float The new circle. Circle
addConstraint(self, constraint, item1=None, item2=None)

Adds a constraint for one or two items.

param constraint:
The constraint.
type constraint:
enum
param item1:The item to hold the constraint.
type item1:InterfaceItem
param item2:The item to hold the constraint.
type item2:InterfaceItem
returns:The new constraint.
rtype:Constraint
addDimension(self, dimension, value=None, item1=None, item2=None)

Defines constrain the dimensions of a sketch.

param dimension:
The type of dimension.
type dimension:enum
param value:The value of the dimension.
param item1:The item to hold the constraint.
type item1:InterfaceItem
param item2:The item to hold the constraint.
type item2:InterfaceItem
returns:The new dimension.
rtype:Dimension
addEllipse(self, center, verticalAxis, majorRadius, minorRadius)

param center: type center: The center of the ellipse. tuple[float, float] The verical axis of the ellipse. tuple[float, float] The major radius of the ellipse. float The minor radius of the ellipse. float The new ellipse. Ellipse
addLine(self, point, direction)

Adds a line with the specified direction, that goes through a point.

param point: type point: The point of the line. Union[Point, tuple[float, float]] The direction of the line. tuple[float, float] The new line. Line
addLineSegment(self, point1, point2)

Adds a line segment defined by two endpoints.

param point1: The endpoint of the line. Union[Point, tuple[float, float]] The endpoint of the line. Union[Point, tuple[float, float]] The new line segment. Line
addParallelogram(self, lowerLeft, lowerRight, upperRight)

Adds a parallelogram defined 3 vertex.

param lowerLeft:
The lower left point of of the parallelogram.
type lowerLeft:tuple[float, float]
param lowerRight:
The lower right point of of the parallelogram.
type lowerRight:
tuple[float, float]
param upperRight:
The lower right point of of the parallelogram.
type upperRight:
tuple[float, float]
returns:The points and lines of the parallelogram.
rtype:tuple[list[Points], list[Lines]]
addPoint(self, x, y)

Adds a Point to the Sketch at defined position.

param x: The x coordinate of the point. float The y coordinate of the point. float The new Point. Point
addPolyline(self, points)

Adds a Polyline of line segments that go through the specified points.

param points (List[tuple[float, float]]:
The points of the polyline.
returns:The new created polyline.
rtype:Polyline
addRectangle2Vertex(self, vertex1, vertex2)

Adds a rectangle aligned with sketch axis defined by two vertex.

param vertex1: A vertex of the rectangle. tuple[float, float] A vertex of the rectangle. tuple[float, float] The points and lines of the rectangle. tuple[list[Points], list[Lines]]
addRectangle3Vertex(self, lowerLeft, lowerRight, upperRight)

Adds a rectangle defined by three vertex.

param lowerLeft:
The lower left point of the rectangle.
type lowerLeft:tuple[float, float]
param lowerRight:
The lower right point of the rectangle.
type lowerRight:
tuple[float, float]
param upperRight:
The upper right point of the rectangle.
type upperRight:
tuple[float, float]
returns:The points and lines of the rectangle.
rtype:tuple[list[Points], list[Lines]]
addRectangleCenter2Points(self, center, lengthPoint, widthPoint)

Adds a rectangle defined by center and two vertex.

param center: type center: The center of the rectangle. tuple[float, float] A vertex of the rectangle. tuple[float, float] A vertex of the rectangle. tuple[float, float] The points and lines of the rectangle. tuple[list[Points], list[Lines]]
addRectangleCenterVertex(self, center, vertex)

Adds a rectangle aligned with sketch axis defined by center and one vertex.

param center: The center of the rectangle. tuple[float, float] A vertex of the rectangle. tuple[float, float] The points and lines of the rectangle. tuple[list[Points], list[Lines]]
addRegularPolygon(self, center, point, numSides, beMidPoint=False)

Adds a regular polygon defined by center, one vertex and the number of sides.

param center: type center: The center of the regular polygon. tuple[float, float] A vertex of the regular polygon. tuple[float, float] The number of sides. int bool The points and lines of the rectangle. tuple[list[Points], list[Lines]]
addSpline(self, points, degree=3, periodic=False, interpolated=False)

Adds a spline based on a list of points.

param points: type points: The points of the spline. list[Point] The degree. int Determines whether it is periodic. bool Determines whether it should get interpolated. bool The new spline. Spline
deleteItem(self, item)

Removes an item from the sketch.

param item: The item to be removed. InterfaceItem True if the item has been successfully removed, False otherwise. bool
evaluate(self)

Recalculates sketch items according to constraints.

extend(self, curvePoint, limitPoint)

Extend or shorten an entity of a sketch curve.

param curvePoint:
The point of the curve to extend.
type curvePoint:
tuple[float, float]
param limitPoint:
The point of the limit curve.
type limitPoint:
tuple[float, float]
returns:True on success, False otherwise.
rtype:bool
fillet(self, vertices, radius=0)

Fillet a list of vertices with the specified radius.

param vertices: The vertices to be filleted. list[Points], The fillet radius. float True on success, False otherwise. bool
findCircle(self, uid)

Returns the Circle with the specified id.

findConstraint(self, uid)

Returns the Constraint with the specified id.

findEllipse(self, uid)

Returns the Ellipse with the specified id.

findItem(self, uid)

Returns the InterfaceItem with the specified id.

findLine(self, uid)

Returns the Line with the specified id.

findPoint(self, uid)

Returns the Point with the specified id.

findSpline(self, uid)

Returns the Spline with the specified id.

getCircleCenter(self, circle)

Returns the circle center.

getCircleRadius(self, circle)

getDimensionVariableName(self, dimension)

Gets the variable of a dimension.

param dimension:
The dimension.
type dimension:Constraint
returns:The name of the variable.
rtype:str
getEndPoints(self, item)

Returns the item endpoints as a PointVector.

getItemStatus(self, item)

Returns the status of item according the ITEM_STATUS enum.

getLineDirection(self, line)

Returns the line direction.

getLinePosition(self, line)

Returns the line position.

getPointPosition(self, point)

Returns the point position.

hasCircle(self, uid)

Returns True if sketch contains a Point with the specified id, False otherwise.

hasConstraint(self, uid)

Returns True if sketch contains a Point with the specified id, False otherwise.

hasEllipse(self, uid)

Returns True if sketch contains a Point with the specified id.

hasItem(self, uid)

Returns True if sketch contains a Point with the specified id, False otherwise.

hasLine(self, uid)

Returns True if sketch contains a Point with the specified id, False otherwise.

hasPoint(self, uid)

Returns True if sketch contains a Point with the specified id, False otherwise.

hasSpline(self, uid)

Returns True if sketch contains a Point with the specified id, False otherwise.

isBounded(self, item)

Returns True if the item is bounded, False otherwise.

mirror(self, curves, mirrorLine)

Creates symmetric copies of selected sketch curves across a selected centerline.

By default, there is a parent-child relationship between source curves and their symmetric copies.

param vertices: type vertices: The curves to be mirrored. list[InterfaceItem] The mirror line. Line True if all items have been mirrored, False otherwise. bool
offset(self, point, distance)

Creates a copy of a sketch curve at a specified distance from the source curve.

param point: tuple[float, float] float True on success, False otherwise. bool
parameterManager(self)

Return the Parameter Manager for this sketch

polylineAddArcTo(self, polyline, arcTo, direction)

Adds an arc from the polyline last point to the specified Point.

param polyline: type polyline: The polyline that is being constructed. Polyline The position of the endpoint of the new arc. tuple[float, float] The initial direction of the arc. enum True if the arc was successfully added to the polyline, False otherwise. bool
polylineAddLineTo(self, polyline, pointTo)

Adds a line segment from the polyline last point to the specified Point.

param polyline: The polyline that is being constructed. Polyline The position of the endpoint of the new line. tuple[float, float] True if the arc was successfully added to the polyline, False otherwise. bool
polylineEnd(self, polyline)

Finishs the construction of the polyline.

param polyline: The polyline that is being constructed. Polyline The points and lines of the polyline. tuple[list[Points], list[Lines]]
polylineStart(self, x, y)

Starts the creation of a polyline on a specified Point.

param x: The x coordinate of the first point. float The y coordinate of the first point. float The new created polyline. Polyline
populate(self)

Redraws the sketch if required.

setDimensionVariable(self, dimension, varName)

Sets a variable as value for a dimension.

param dimension:
The dimension.
type dimension:Constraint
param varName:The name of the variable.
type varName:str
setParameterManager(self, pm)

Set the Parameter Manager to use for this sketch

setPointPosition(self, point, position)

Set a Point position.

param point: The point. Point The new position of the point. tuple[float, float] True if the new position was successfully set, False otherwise. bool
setWorkplane(self, name='main', origin=None, normal=None, horizontalAxis=None)

Sets the name, plane and coordinate system of the sketch.

A sketch plane can be a global plane, a user-created reference plane, or a planar face of an existing part.

param name: type name: The name of the workplane. str, optional The coordinates of the origin point of the sketch. tuple[float, float, float], optional The normal vector to the sketch plane. tuple[float, float, float], optional The direction of the x axis of the sketch. tuple[float, float, float], optional
split(self, curvePoint, breakPoint)

Split a curve in two at a defined break point.

param curvePoint:
The point of the curve to be splitted.
type curvePoint:
tuple[float, float]
param breakPoint:
The point of break.
type breakPoint:
tuple[float, float]
returns:True on success, False otherwise.
rtype:bool
trim(self, x, y)

Removes one or more geometric entities below the (x, y) coordinates of the sketch curve.

param x: The x coordinate. float The y coordinate. float True if a geometric entity was trimmed, False otherwise. bool
update(self)

Evaluates and populates the sketch.