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, mirrorAxis=None)
addDimension (self, dimension, value=None, item1=None, item2=None, x=1.7976931348623157e+308, y=1.7976931348623157e+308, pickX=1.7976931348623157e+308, pickY=1.7976931348623157e+308)
addEllipse (self, center, verticalAxis, majorRadius, minorRadius=None)
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)
circularPattern (self, entities, point, copy, angle, symmetry)
deleteItem (self, item)
enableHistory (self, state=True)
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)
getDimensionVariableName (self, dimension)
getEndPoints (self, item)
getItemStatus (self, item)
hasCircle (self, uid)
hasConstraint (self, uid)
hasEllipse (self, uid)
hasItem (self, uid)
hasLine (self, uid)
hasPoint (self, uid)
hasSpline (self, uid)
isConstruction (self, item)
isDimensionDriven (self, item)
isFixed (self, item)
linearPattern (self, entities, direction1, copy1, distance1, symmetry1, direction2=None, copy2=None, distance2=None, symmetry2=None)
mirror (self, curves, mirrorLine)
offset (self, point, distance)
origin (self)
parameterManager (self)
polylineAddArcTo (self, polyline, arcTo, direction)
polylineAddLineTo (self, polyline, pointTo)
polylineEnd (self, polyline)
polylineStart (self, x, y)
populate (self)
rotate (self, entities, center, angle, keepRelations=True)
setConstruction (self, item, state=True)
setDimensionIsDriven (self, item, state)
setDimensionVariable (self, dimension, varName)
setFixed (self, item, state=True)
setParameterManager (self, pm)
setWorkplane (self, matrix)
split (self, curvePoint, breakPoint)
translate (self, entities, direction, value, keepRelations=True)
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
Point | tuple[float, float]
- param end
The end point of the arc.
- type end
Point | tuple[float, float]
- param third
An another point of the arc.
- type third
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
Point | tuple[float, float]
- param point1
The point of the circle.
- type point1
Point | tuple[float, float]
- param point2
The point of the circle.
- type point2
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 | tuple[float, float]
- param end
The end point of the arc.
- type end
Point | 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
Point | tuple[float, float]
- param majorAxisPoint
The start point defining the major axis.
- type majorAxisPoint
Line | tuple[float, float]
- param minorAxisPoint
The end point defining the major axis.
- type minorAxisPoint
Line | tuple[float, float]
- param start
The start point of the ellipse.
- type start
Point | tuple[float, float]
- param end
The end point of the ellipse.
- type end
Point | 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
Point | tuple[float, float]
- param point2
The endpoint of the diameter.
- type point2
Point | tuple[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
Point | tuple[float, float]
- param point2
The point of the circle.
- type point2
Point | tuple[float, float]
- param point3
The point of the circle.
- type point3
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
Point | tuple[float, float]
- param point
The point of the circle.
- type point
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
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, mirrorAxis=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
- param mirrorAxis
The item for a mirror constraints axis.
- type mirrorAxis
InterfaceItem
- returns
The new constraint.
- rtype
Constraint
- addDimension(self, dimension, value=None, item1=None, item2=None, x=1.7976931348623157e+308, y=1.7976931348623157e+308, pickX=1.7976931348623157e+308, pickY=1.7976931348623157e+308)¶
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=None)¶
Adds an ellipse defined by center, vertical axis and radius, or by center Point, and Line for major axis and Line for minor axis.
- param center
The center of the ellipse.
- type center
Point | tuple[float, float]
- param verticalAxis
For a Line, the majorAxis, otherwise the vertical axis of the ellipse.
- type verticalAxis
Line | tuple[float, float]
- param majorRadius
For a Line, the minor axis, otherwie the major radius of the ellipse.
- type majorRadius
Line | 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
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
Point | tuple[float, float]
- param point2
The endpoint of the line.
- type point2
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
The points of the polyline.
- param 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[tuple[float, float]]| 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
- circularPattern(self, entities, point, copy, angle, symmetry)¶
Pattern sketch entities around a point.
- param entities
Sketch curve entity to create linear pattern.
- type entities
list[SketchItem]
- param point
Center Point for circular sketch pattern.
- type point
Point
- param copy
Number of copies.
- type copy
int
- param angle
Distance between two copies in direction 1.
- type angle
float
- param symmetry
Symmetry in Direction 1.
- type symmetry
bool
- returns
CircularPattern Object.
- rtype
CircularPattern
- 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
- enableHistory(self, state=True)¶
Set the state of the abilty to store history
- 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.
- 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.
- 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.
- isConstruction(self, item)¶
Returns True if the item is a construction item, False otherwise.
- isDimensionDriven(self, item)¶
Returns True if the item is a dimension and is driven, False otherwise.
- isFixed(self, item)¶
Returns True if the item is fixed, False otherwise.
- linearPattern(self, entities, direction1, copy1, distance1, symmetry1, direction2=None, copy2=None, distance2=None, symmetry2=None)¶
Pattern sketch entities in a linear direction.
- param entities
Sketch curve entity to create linear pattern.
- type entities
list[SketchItem]
- param direction1
Direction 1 for sketch pattern.
- type direction1
Line
- param copy1
Number of copies in direction 1.
- type copy1
int
- param distance1
Distance between two copies in direction 1.
- type distance1
float
- param symmetry1
Symmetry in Direction 1.
- type symmetry1
bool
- param direction2
Direction 2 for sketch pattern.
- type direction2
Line
- param copy2
Number of copies in direction 2.
- type copy2
int
- param distance2
Distance between two copies in direction 2.
- type distance2
float
- param symmetry2
Symmetry in Direction 2.
- type symmetry2
bool
- returns
LinearPattern Object.
- rtype
LinearPattern
- 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
- origin(self)¶
Returns the Point for the origin.
- 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.
- rotate(self, entities, center, angle, keepRelations=True)¶
Rotate Sketch entities.
- param entities
Sketch entity to rotate.
- type entities
list[SketchItem]
- param center
Center point to rotate sketch entity.
- type center
Point
- param angle
Rotation angle for sketch entity.
- type angle
float
- param keepRelations
Keep relations between sketch entities after rotation.
- type keepRelations
bool
- returns
True on success, False otherwise.
- rtype
bool
- setConstruction(self, item, state=True)¶
Set the items construction flag.
- setDimensionIsDriven(self, item, state)¶
Returns True if the item is a dimension and is driven, False otherwise.
- 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
- setFixed(self, item, state=True)¶
Set the items fixed state.
- setParameterManager(self, pm)¶
Set the Parameter Manager to use for this sketch
- setWorkplane(self, matrix)¶
Define the workplane from the passed matrix.
- 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
- translate(self, entities, direction, value, keepRelations=True)¶
Translate Sketch entities.
- param entities
Sketch entity to translate.
- type entities
list[SketchItem]
- param direction
Direction for sketch translation.
- type direction
tuple[float, float]
- param value
Translate value for sketch entity.
- type value
float
- param keepRelations
Keep relations between sketch entities after translation.
- type keepRelations
bool
- 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.