Sketch (hwx.common)#
- class Sketch(Interface=None)#
Bases:
object
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.
Attribute Table# Name
Type
CONSTRAINT_ANGLE
int
CONSTRAINT_COINCIDENT
int
CONSTRAINT_COLLINEAR
int
CONSTRAINT_CONCENTRIC
int
CONSTRAINT_DIAMETER_ALIGNED
int
CONSTRAINT_DIAMETER_HORIZONTAL
int
CONSTRAINT_DIAMETER_VERTICAL
int
CONSTRAINT_DISTANCE_ALIGNED
int
CONSTRAINT_DISTANCE_HORIZONTAL
int
CONSTRAINT_DISTANCE_VERTICAL
int
CONSTRAINT_EQUAL
int
CONSTRAINT_FIXED
int
CONSTRAINT_HORIZONTAL
int
CONSTRAINT_HORIZONTAL_POINTS
int
CONSTRAINT_MAJOR_RADIUS
int
CONSTRAINT_MIDPOINT
int
CONSTRAINT_MINOR_RADIUS
int
CONSTRAINT_MIRROR
int
CONSTRAINT_OFFSET
int
CONSTRAINT_OFFSET_DISTANCE
int
CONSTRAINT_PARALLEL
int
CONSTRAINT_PERPENDICULAR
int
CONSTRAINT_RADIUS
int
CONSTRAINT_TANGENT
int
CONSTRAINT_VERTICAL
int
CONSTRAINT_VERTICAL_POINTS
int
DIMENSION_ANGLE
int
DIMENSION_DIAMETER_ALIGNED
int
DIMENSION_DIAMETER_HORIZONTAL
int
DIMENSION_DIAMETER_VERTICAL
int
DIMENSION_DISTANCE_ALIGNED
int
DIMENSION_DISTANCE_HORIZONTAL
int
DIMENSION_DISTANCE_VERTICAL
int
DIMENSION_MAJOR_RADIUS
int
DIMENSION_MINOR_RADIUS
int
DIMENSION_OFFSET_DISTANCE
int
DIMENSION_RADIUS
int
STATUS_FIXED
int
STATUS_FULLYDEFINED
int
STATUS_NOTCHANGED
int
STATUS_NOTCONSISTENT
int
STATUS_OVERDEFINED
int
STATUS_UNDERDEFINED
int
STATUS_UNKNOWN
int
TANGENT_INWARD
int
TANGENT_NORMAL_LEFT
int
TANGENT_NORMAL_RIGHT
int
TANGENT_OUTWARD
int
workplane
property
Method Table# Name
Description
addArc3Points
(self, start, end, third)Adds an arc by defining three points.
addArcCenter2Points
(self, center, point1, point2, ccw=True)Adds an Arc defined by its center and its endpoints.
addArcTangentTo
(self, tangentTo, start, end, bInvertTangent=False)Adds an arc, starting tangent to a curve on a start point and ending on
addBoundedEllipse
(self, center, majorAxisPoint, minorAxisPoint, start, end, bCounterClockWise=False)Adds an ellipse defined by center, two points that define an axis and
addCircle2Points
(self, point1, point2)Adds a circle defined by the 2 endpoints of a diameter.
addCircle3Points
(self, point1, point2, point3)Adds a circle defined by three points.
addCircleCenterPoint
(self, center, point)Adds a circle defined by its center and one point.
addCircleCenterRadius
(self, center, radius)Adds a circle defined by its center and radius.
addConstraint
(self, constraint, item1=None, item2=None, mirrorAxis=None)Adds a constraint for one or two items.
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.
addEllipse
(self, center, verticalAxis, majorRadius, minorRadius=None)Adds an ellipse defined by center, vertical axis and radius, or
addLine
(self, point, direction)Adds a line with the specified direction, that goes through a point.
addLineSegment
(self, point1, point2)Adds a line segment defined by two endpoints.
addParallelogram
(self, lowerLeft, lowerRight, upperRight)Adds a parallelogram defined 3 vertex.
addPoint
(self, x, y)addPolyline
(self, points)Adds a Polyline of line segments that go through the specified points.
addRectangle2Vertex
(self, vertex1, vertex2)Adds a rectangle aligned with sketch axis defined by two vertex.
addRectangle3Vertex
(self, lowerLeft, lowerRight, upperRight)Adds a rectangle defined by three vertex.
addRectangleCenter2Points
(self, center, lengthPoint, widthPoint)Adds a rectangle defined by center and two vertex.
addRectangleCenterVertex
(self, center, vertex)Adds a rectangle aligned with sketch axis defined by center and one vertex.
addRegularPolygon
(self, center, point, numSides, beMidPoint=False)Adds a regular polygon defined by center, one vertex and the number of sides.
addSpline
(self, points, degree=3, periodic=False, interpolated=False)Adds a spline based on a list of points.
circularPattern
(self, entities, point, copy, angle, symmetry, createDimension=True, equalSpacing=False)Pattern sketch entities around a point.
deleteItem
(self, item)Removes an item from the sketch.
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.
fillet
(self, vertices, radius=0)Fillet a list of vertices with the specified radius.
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.
getActive
()Sketch currently being edited in the gui.
getDimensionVariableName
(self, dimension)Gets the variable of a dimension.
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.
isAnyOverConstrained
(self)Returns True if and items are over constrained, 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=3, distance1=0.1, symmetry1=False, direction2=None, copy2=3, distance2=0.1, symmetry2=False)Pattern sketch entities in a linear direction.
mirror
(self, curves, mirrorLine)Creates symmetric copies of selected sketch curves across a selected
offset
(self, point, distance)Creates a copy of a sketch curve at a specified distance from the source curve.
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.
polylineAddLineTo
(self, polyline, pointTo)Adds a line segment from the polyline last point to the specified Point.
polylineEnd
(self, polyline)Finishs the construction of the polyline.
polylineStart
(self, x, y)Starts the creation of a polyline on a specified Point.
populate
(self)Redraws the sketch if required.
rotate
(self, entities, center, angle, keepRelations=True)Rotate Sketch entities.
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.
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.
translate
(self, entities, direction, value, keepRelations=True)Translate Sketch entities.
trim
(self, x, y)Removes one or more geometric entities below the (x, y) coordinates of
update
(self)Evaluates and populates the sketch.
Example
Define and use Splines.#from hwx import inspire from hwx.common.Sketch import Sketch model = inspire.newModel() # instanciate sketch s = Sketch() # instantiate points p1 = s.addPoint(2, 2) p2 = s.addPoint(1, 1) # we can also query and set the position of point p1. position = p1.position print(f'Position of p1: {position}') p1.position = (0, 0) print(f'Position of p1 after change: {p1.position}') # instantiate line segment using points or coordinates ls1 = s.addLineSegment(p1, p2) ls2 = s.addLineSegment((2, 2), (4, 4)) # instantiate line using point and direction l1 = s.addLine((3, 3), (1, -1)) # we can also query the position of line l1. print(f'Position and direction of l1 : {l1.position}, {l1.direction}') s.addLine(p1, (1, 0))
- setWorkplane(matrix)#
Define the workplane from the passed matrix.
- isConstruction(item)#
Returns True if the item is a construction item, False otherwise.
- setConstruction(item, state=True)#
Set the items construction flag.
- isFixed(item)#
Returns True if the item is fixed, False otherwise.
- setFixed(item, state=True)#
Set the items fixed state.
- isAnyOverConstrained()#
Returns True if and items are over constrained, False otherwise.
- enableHistory(state=True)#
Set the state of the abilty to store history
- addPoint(x, y)#
Adds a Point to the Sketch at defined position.
- Parameters:
x (float) – The x coordinate of the point.
y (float) – The y coordinate of the point.
- Returns:
The new Point.
- Return type:
- addLine(point, direction)#
Adds a line with the specified direction, that goes through a point.
- Parameters:
point (Point | tuple[float, float]) – The point of the line.
direction (tuple[float, float]) – The direction of the line.
- Returns:
The new line.
- Return type:
Line
- addLineSegment(point1, point2)#
Adds a line segment defined by two endpoints.
- addCircleCenterRadius(center, radius)#
Adds a circle defined by its center and radius.
- Parameters:
center (Point | tuple[float, float]) – The center of the circle.
radius (float) – The radius of the circle.
- Returns:
The new circle.
- Return type:
Circle
- addCircleCenterPoint(center, point)#
Adds a circle defined by its center and one point.
- addCircle2Points(point1, point2)#
Adds a circle defined by the 2 endpoints of a diameter.
- addCircle3Points(point1, point2, point3)#
Adds a circle defined by three points.
- addArcCenter2Points(center, point1, point2, ccw=True)#
Adds an Arc defined by its center and its endpoints.
- Parameters:
- Returns:
The new arc.
- Return type:
Circle
- addArc3Points(start, end, third)#
Adds an arc by defining three points.
- addArcTangentTo(tangentTo, start, end, bInvertTangent=False)#
- Adds an arc, starting tangent to a curve on a start point and ending on
a defined point.
- Parameters:
- Returns:
The new arc.
- Return type:
Circle
- addEllipse(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.
- Parameters:
center (Point | tuple[float, float]) – The center of the ellipse.
verticalAxis (Line | tuple[float, float]) – For a Line, the majorAxis, otherwise the vertical axis of the ellipse.
majorRadius (Line | float) – For a Line, the minor axis, otherwie the major radius of the ellipse.
minorRadius (float) – The minor radius of the ellipse.
- Returns:
The new ellipse.
- Return type:
Ellipse
- addBoundedEllipse(center, majorAxisPoint, minorAxisPoint, start, end, bCounterClockWise=False)#
Adds an ellipse defined by center, two points that define an axis and start and end points.
- Parameters:
center (Point | tuple[float, float]) – The center of the ellipse.
majorAxisPoint (Line | tuple[float, float]) – The start point defining the major axis.
minorAxisPoint (Line | tuple[float, float]) – The end point defining the major axis.
start (Point | tuple[float, float]) – The start point of the ellipse.
end (Point | tuple[float, float]) – The end point of the ellipse.
bCounterClockWise (bool) – Determines whether to use counter clockwise direction from start to end or not.
- Returns:
The new ellipse.
- Return type:
Ellipse
- addSpline(points, degree=3, periodic=False, interpolated=False)#
Adds a spline based on a list of points.
- addPolyline(points)#
Adds a Polyline of line segments that go through the specified points.
- Parameters:
(list[tuple[float (points) – The points of the polyline.
float]] – The points of the polyline.
- Returns:
The new created polyline.
- Return type:
Polyline
- polylineStart(x, y)#
Starts the creation of a polyline on a specified Point.
- Parameters:
x (float) – The x coordinate of the first point.
y (float) – The y coordinate of the first point.
- Returns:
The new created polyline.
- Return type:
Polyline
- polylineAddLineTo(polyline, pointTo)#
Adds a line segment from the polyline last point to the specified Point.
- Parameters:
polyline (Polyline) – The polyline that is being constructed.
pointTo (tuple[float, float]) – The position of the endpoint of the new line.
- Returns:
True if the arc was successfully added to the polyline, False otherwise.
- Return type:
bool
- polylineAddArcTo(polyline, arcTo, direction)#
Adds an arc from the polyline last point to the specified Point.
- Parameters:
polyline (Polyline) – The polyline that is being constructed.
arcTo (tuple[float, float]) – The position of the endpoint of the new arc.
direction (enum) – The initial direction of the arc.
- Returns:
True if the arc was successfully added to the polyline, False otherwise.
- Return type:
bool
- polylineEnd(polyline)#
Finishs the construction of the polyline.
- Parameters:
polyline (Polyline) – The polyline that is being constructed.
- Returns:
The points and lines of the polyline.
- Return type:
tuple[list[Points], list[Lines]]
- addRectangleCenterVertex(center, vertex)#
Adds a rectangle aligned with sketch axis defined by center and one vertex.
- Parameters:
center (tuple[float, float]) – The center of the rectangle.
vertex (tuple[float, float]) – A vertex of the rectangle.
- Returns:
The points and lines of the rectangle.
- Return type:
tuple[list[Points], list[Lines]]
- addRectangle2Vertex(vertex1, vertex2)#
Adds a rectangle aligned with sketch axis defined by two vertex.
- Parameters:
vertex1 (tuple[float, float]) – A vertex of the rectangle.
vertex2 (tuple[float, float]) – A vertex of the rectangle.
- Returns:
The points and lines of the rectangle.
- Return type:
tuple[list[Points], list[Lines]]
- addRectangle3Vertex(lowerLeft, lowerRight, upperRight)#
Adds a rectangle defined by three vertex.
- Parameters:
lowerLeft (tuple[float, float]) – The lower left point of the rectangle.
lowerRight (tuple[float, float]) – The lower right point of the rectangle.
upperRight (tuple[float, float]) – The upper right point of the rectangle.
- Returns:
The points and lines of the rectangle.
- Return type:
tuple[list[Points], list[Lines]]
- addRectangleCenter2Points(center, lengthPoint, widthPoint)#
Adds a rectangle defined by center and two vertex.
- Parameters:
center (tuple[float, float]) – The center of the rectangle.
lengthPoint (tuple[float, float]) – A vertex of the rectangle.
widthPoint (tuple[float, float]) – A vertex of the rectangle.
- Returns:
The points and lines of the rectangle.
- Return type:
tuple[list[Points], list[Lines]]
- addParallelogram(lowerLeft, lowerRight, upperRight)#
Adds a parallelogram defined 3 vertex.
- Parameters:
lowerLeft (tuple[float, float]) – The lower left point of of the parallelogram.
lowerRight (tuple[float, float]) – The lower right point of of the parallelogram.
upperRight (tuple[float, float]) – The lower right point of of the parallelogram.
- Returns:
The points and lines of the parallelogram.
- Return type:
tuple[list[Points], list[Lines]]
- addRegularPolygon(center, point, numSides, beMidPoint=False)#
Adds a regular polygon defined by center, one vertex and the number of sides.
- Parameters:
center (tuple[float, float]) – The center of the regular polygon.
point (tuple[float, float]) – A vertex of the regular polygon.
numSides (int) – The number of sides.
beMidPoint (bool) –
- Returns:
The points and lines of the rectangle.
- Return type:
tuple[list[Points], list[Lines]]
- addConstraint(constraint, item1=None, item2=None, mirrorAxis=None)#
Adds a constraint for one or two items.
- Parameters:
constraint (enum) – The constraint.
item1 (InterfaceItem) – The item to hold the constraint.
item2 (InterfaceItem) – The item to hold the constraint.
mirrorAxis (InterfaceItem) – The item for a mirror constraints axis.
- Returns:
The new constraint.
- Return type:
- addDimension(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.
- Parameters:
dimension (enum) – The type of dimension.
value – The value of the dimension.
item1 (InterfaceItem) – The item to hold the constraint.
item2 (InterfaceItem) – The item to hold the constraint.
- Returns:
The new dimension.
- Return type:
Dimension
- isDimensionDriven(item)#
Returns True if the item is a dimension and is driven, False otherwise.
- setDimensionIsDriven(item, state)#
Returns True if the item is a dimension and is driven, False otherwise.
- deleteItem(item)#
Removes an item from the sketch.
- Parameters:
item (InterfaceItem) – The item to be removed.
- Returns:
True if the item has been successfully removed, False otherwise.
- Return type:
bool
- getEndPoints(item)#
Returns the item endpoints as a PointVector.
- getItemStatus(item)#
Returns the status of item according the ITEM_STATUS enum.
- setDimensionVariable(dimension, varName)#
Sets a variable as value for a dimension.
- Parameters:
dimension (Constraint) – The dimension.
varName (str) – The name of the variable.
- getDimensionVariableName(dimension)#
Gets the variable of a dimension.
- Parameters:
dimension (Constraint) – The dimension.
- Returns:
The name of the variable.
- Return type:
str
- update()#
Evaluates and populates the sketch.
- populate()#
Redraws the sketch if required.
- evaluate()#
Recalculates sketch items according to constraints.
- origin()#
Returns the Point for the origin.
- findPoint(uid)#
Returns the Point with the specified id.
- findLine(uid)#
Returns the Line with the specified id.
- findCircle(uid)#
Returns the Circle with the specified id.
- findEllipse(uid)#
Returns the Ellipse with the specified id.
- findSpline(uid)#
Returns the Spline with the specified id.
- findConstraint(uid)#
Returns the Constraint with the specified id.
- findItem(uid)#
Returns the InterfaceItem with the specified id.
- hasPoint(uid)#
Returns True if sketch contains a Point with the specified id, False otherwise.
- hasLine(uid)#
Returns True if sketch contains a Point with the specified id, False otherwise.
- hasCircle(uid)#
Returns True if sketch contains a Point with the specified id, False otherwise.
- hasEllipse(uid)#
Returns True if sketch contains a Point with the specified id.
- hasSpline(uid)#
Returns True if sketch contains a Point with the specified id, False otherwise.
- hasConstraint(uid)#
Returns True if sketch contains a Point with the specified id, False otherwise.
- hasItem(uid)#
Returns True if sketch contains a Point with the specified id, False otherwise.
- split(curvePoint, breakPoint)#
Split a curve in two at a defined break point.
- Parameters:
curvePoint (tuple[float, float]) – The point of the curve to be splitted.
breakPoint (tuple[float, float]) – The point of break.
- Returns:
True on success, False otherwise.
- Return type:
bool
- extend(curvePoint, limitPoint)#
Extend or shorten an entity of a sketch curve.
- Parameters:
curvePoint (tuple[float, float]) – The point of the curve to extend.
limitPoint (tuple[float, float]) – The point of the limit curve.
- Returns:
True on success, False otherwise.
- Return type:
bool
- fillet(vertices, radius=0)#
Fillet a list of vertices with the specified radius.
- Parameters:
vertices (list[Points],) – The vertices to be filleted.
radius (float) – The fillet radius.
- Returns:
True on success, False otherwise.
- Return type:
bool
- mirror(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.
- Parameters:
vertices (list[InterfaceItem]) – The curves to be mirrored.
mirrorLine (Line) – The mirror line.
- Returns:
True if all items have been mirrored, False otherwise.
- Return type:
bool
- trim(x, y)#
Removes one or more geometric entities below the (x, y) coordinates of the sketch curve.
- Parameters:
x (float) – The x coordinate.
y (float) – The y coordinate.
- Returns:
True if a geometric entity was trimmed, False otherwise.
- Return type:
bool
- offset(point, distance)#
Creates a copy of a sketch curve at a specified distance from the source curve.
- Parameters:
point (tuple[float, float]) –
distance (float) –
- Returns:
True on success, False otherwise.
- Return type:
bool
- linearPattern(entities, direction1, copy1=3, distance1=0.1, symmetry1=False, direction2=None, copy2=3, distance2=0.1, symmetry2=False)#
Pattern sketch entities in a linear direction.
- Parameters:
entities (list[SketchItem]) – Sketch curve entity to create linear pattern.
direction1 (Line) – Direction 1 for sketch pattern.
copy1 (int) – Number of copies in direction 1.
distance1 (float) – Distance between two copies in direction 1.
symmetry1 (bool) – Symmetry in Direction 1.
direction2 (Line) – Direction 2 for sketch pattern.
copy2 (int) – Number of copies in direction 2.
distance2 (float) – Distance between two copies in direction 2.
symmetry2 (bool) – Symmetry in Direction 2.
- Returns:
LinearPattern Object.
- Return type:
LinearPattern
- circularPattern(entities, point, copy, angle, symmetry, createDimension=True, equalSpacing=False)#
Pattern sketch entities around a point.
- Parameters:
entities (list[SketchItem]) – Sketch curve entity to create linear pattern.
point (Point) – Center Point for circular sketch pattern.
copy (int) – Number of copies.
angle (float) – Distance between two copies in direction 1.
symmetry (bool) – Symmetry in Direction 1.
createDimension (bool) – If True, dimension is added otherwise not.
equalSpacing (bool) – If True, equally space the copies otherwise not.
- Returns:
CircularPattern Object.
- Return type:
CircularPattern
- translate(entities, direction, value, keepRelations=True)#
Translate Sketch entities.
- Parameters:
entities (list[SketchItem]) – Sketch entity to translate.
direction (tuple[float, float]) – Direction for sketch translation.
value (float) – Translate value for sketch entity.
keepRelations (bool) – Keep relations between sketch entities after translation.
- Returns:
True on success, False otherwise.
- Return type:
bool
- rotate(entities, center, angle, keepRelations=True)#
Rotate Sketch entities.
- Parameters:
entities (list[SketchItem]) – Sketch entity to rotate.
center (Point) – Center point to rotate sketch entity.
angle (float) – Rotation angle for sketch entity.
keepRelations (bool) – Keep relations between sketch entities after rotation.
- Returns:
True on success, False otherwise.
- Return type:
bool
- parameterManager()#
Return the Parameter Manager for this sketch
- setParameterManager(pm)#
Set the Parameter Manager to use for this sketch