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.

Public Methods

addArc3Points (self, start, end, third)
addArcCenter2Points (self, center, point1, point2, ccw=True)
addArcTangentTo (self, tangentTo, start, end, bInvertTangent=False)
addBoundedEllipse (self, center, majorAxisPoint, minorAxisPoint, start, end, bCounterClockWise=False)
addCircle2Points (self, point1, point2)
addCircle3Points (self, point1, point2, point3)
addCircleCenterPoint (self, center, point)
addCircleCenterRadius (self, center, radius)
addConstraint (self, constraint, item1=None, item2=None)
addDimension (self, dimension, value=None, item1=None, item2=None)
addEllipse (self, center, verticalAxis, majorRadius, minorRadius)
addLine (self, point, direction)
addLineSegment (self, point1, point2)
addParallelogram (self, lowerLeft, lowerRight, upperRight)
addPoint (self, x, y)
addPolyline (self, points)
addRectangle2Vertex (self, vertex1, vertex2)
addRectangle3Vertex (self, lowerLeft, lowerRight, upperRight)
addRectangleCenter2Points (self, center, lengthPoint, widthPoint)
addRectangleCenterVertex (self, center, vertex)
addRegularPolygon (self, center, point, numSides, beMidPoint=False)
addSpline (self, points, degree=3, periodic=False, interpolated=False)
deleteItem (self, item)
evaluate (self)
extend (self, curvePoint, limitPoint)
fillet (self, vertices, radius=0)
findCircle (self, uid)
findConstraint (self, uid)
findEllipse (self, uid)
findItem (self, uid)
findLine (self, uid)
findPoint (self, uid)
findSpline (self, uid)
getCircleCenter (self, circle)
getCircleRadius (self, circle)
getDimensionVariableName (self, dimension)
getEndPoints (self, item)
getItemStatus (self, item)
getLineDirection (self, line)
getLinePosition (self, line)
getPointPosition (self, point)
hasCircle (self, uid)
hasConstraint (self, uid)
hasEllipse (self, uid)
hasItem (self, uid)
hasLine (self, uid)
hasPoint (self, uid)
hasSpline (self, uid)
isBounded (self, item)
mirror (self, curves, mirrorLine)
offset (self, point, distance)
parameterManager (self)
polylineAddArcTo (self, polyline, arcTo, direction)
polylineAddLineTo (self, polyline, pointTo)
polylineEnd (self, polyline)
polylineStart (self, x, y)
populate (self)
setDimensionVariable (self, dimension, varName)
setParameterManager (self, pm)
setPointPosition (self, point, position)
setWorkplane (self, name=’main’, origin=None, normal=None, horizontalAxis=None)
split (self, curvePoint, breakPoint)
trim (self, x, y)
update (self)

Method Details

addArc3Points(self, start, end, third)

Adds an arc by defining three points.

param start:The start point of the arc.
type start:Union[Point, tuple[float, float]]
param end:The end point of the arc.
type end:Union[Point, tuple[float, float]]
param third:An another point of the arc.
type third:Union[Point, tuple[float, float]]
returns:The new arc.
rtype: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.
type center:Union[Point, tuple[float, float]]
param point1:The point of the circle.
type point1:Union[Point, tuple[float, float]]
param point2:The point of the circle.
type point2:Union[Point, tuple[float, float]]
param ccw:Determines whether to use counter clockwise direction from point1 to point2 or not.
type ccw:bool
returns:The new arc.
rtype: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:The center of the ellipse.
type center:tuple[float, float]
param majorAxisPoint:
 The start point defining the major axis.
type majorAxisPoint:
 tuple[float, float]
param minorAxisPoint:
 The end point defining the major axis.
type minorAxisPoint:
 tuple[float, float]
param start:The start point of the ellipse.
type start:tuple[float, float]
param end:The end point of the ellipse.
type end:tuple[float, float]
param bCounterClockWise:
 Determines whether to use counter clockwise direction from start to end or not.
type bCounterClockWise:
 bool
returns:The new ellipse.
rtype:Ellipse
addCircle2Points(self, point1, point2)

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

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

Adds a circle defined by three points.

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

Adds a circle defined by its center and one point.

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

Adds a circle defined by its center and radius.

param center:The center of the circle.
type center:Union[Point, tuple[float, float]]
param radius:The radius of the circle.
type radius:float
returns:The new circle.
rtype: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)

Adds an ellipse defined by center, vertical axis and radius.

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

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

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

Adds a line segment defined by two endpoints.

param point1:The endpoint of the line.
type point1:Union[Point, tuple[float, float]]
param point2:The endpoint of the line.
type point2:Union[Point, tuple[float, float]]
returns:The new line segment.
rtype: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.
type x:float
param y:The y coordinate of the point.
type y:float
returns:The new Point.
rtype: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.
type vertex1:tuple[float, float]
param vertex2:A vertex of the rectangle.
type vertex2:tuple[float, float]
returns:The points and lines of the rectangle.
rtype: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:The center of the rectangle.
type center:tuple[float, float]
param lengthPoint:
 A vertex of the rectangle.
type lengthPoint:
 tuple[float, float]
param widthPoint:
 A vertex of the rectangle.
type widthPoint:
 tuple[float, float]
returns:The points and lines of the rectangle.
rtype: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.
type center:tuple[float, float]
param vertex:A vertex of the rectangle.
type vertex:tuple[float, float]
returns:The points and lines of the rectangle.
rtype: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:The center of the regular polygon.
type center:tuple[float, float]
param point:A vertex of the regular polygon.
type point:tuple[float, float]
param numSides:The number of sides.
type numSides:int
param beMidPoint:
 
type beMidPoint:
 bool
returns:The points and lines of the rectangle.
rtype: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:The points of the spline.
type points:list[Point]
param degree:The degree.
type degree:int
param periodic:Determines whether it is periodic.
type periodic:bool
param interpolated:
 Determines whether it should get interpolated.
type interpolated:
 bool
returns:The new spline.
rtype:Spline
deleteItem(self, item)

Removes an item from the sketch.

param item:The item to be removed.
type item:InterfaceItem
returns:True if the item has been successfully removed, False otherwise.
rtype: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.
type vertices:list[Points],
param radius:The fillet radius.
type radius:float
returns:True on success, False otherwise.
rtype: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)

Returns the circle radius.

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:The curves to be mirrored.
type vertices:list[InterfaceItem]
param mirrorLine:
 The mirror line.
type mirrorLine:
 Line
returns:True if all items have been mirrored, False otherwise.
rtype:bool
offset(self, point, distance)

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

param point:
type point:tuple[float, float]
param distance:
type distance:float
returns:True on success, False otherwise.
rtype: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:The polyline that is being constructed.
type polyline:Polyline
param arcTo:The position of the endpoint of the new arc.
type arcTo:tuple[float, float]
param direction:
 The initial direction of the arc.
type direction:enum
returns:True if the arc was successfully added to the polyline, False otherwise.
rtype: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.
type polyline:Polyline
param pointTo:The position of the endpoint of the new line.
type pointTo:tuple[float, float]
returns:True if the arc was successfully added to the polyline, False otherwise.
rtype:bool
polylineEnd(self, polyline)

Finishs the construction of the polyline.

param polyline:The polyline that is being constructed.
type polyline:Polyline
returns:The points and lines of the polyline.
rtype: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.
type x:float
param y:The y coordinate of the first point.
type y:float
returns:The new created polyline.
rtype: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.
type point:Point
param position:The new position of the point.
type position:tuple[float, float]
returns:True if the new position was successfully set, False otherwise.
rtype: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:The name of the workplane.
type name:str, optional
param origin:The coordinates of the origin point of the sketch.
type origin:tuple[float, float, float], optional
param normal:The normal vector to the sketch plane.
type normal:tuple[float, float, float], optional
param horizontalAxis:
 The direction of the x axis of the sketch.
type horizontalAxis:
 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.
type x:float
param y:The y coordinate.
type y:float
returns:True if a geometric entity was trimmed, False otherwise.
rtype:bool
update(self)

Evaluates and populates the sketch.