53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
"""
|
|
Marking utilities for `Cq.Workplane`
|
|
|
|
Adds the functions to `Cq.Workplane`:
|
|
1. `tagPoint`
|
|
2. `tagPlane`
|
|
"""
|
|
import cadquery as Cq
|
|
from typing import Union, Tuple
|
|
|
|
|
|
def tagPoint(self, tag: str):
|
|
"""
|
|
Adds a vertex that can be used in `Point` constraints.
|
|
"""
|
|
vertex = Cq.Vertex.makeVertex(0, 0, 0)
|
|
self.eachpoint(vertex.moved, useLocalCoordinates=True).tag(tag)
|
|
|
|
Cq.Workplane.tagPoint = tagPoint
|
|
|
|
|
|
def tagPlane(self, tag: str,
|
|
direction: Union[str, Cq.Vector, Tuple[float, float, float]] = '+Z'):
|
|
"""
|
|
Adds a phantom `Cq.Edge` in the given location which can be referenced in a
|
|
`Axis`, `Point`, or `Plane` constraint.
|
|
"""
|
|
if isinstance(direction, str):
|
|
x, y, z = 0, 0, 0
|
|
assert len(direction) == 2
|
|
sign, axis = direction
|
|
if axis in ('z', 'Z'):
|
|
z = 1
|
|
elif axis in ('y', 'Y'):
|
|
y = 1
|
|
elif axis in ('x', 'X'):
|
|
x = 1
|
|
else:
|
|
assert False, "Axis must be one of x,y,z"
|
|
if sign == '+':
|
|
sign = 1
|
|
elif sign == '-':
|
|
sign = -1
|
|
else:
|
|
assert False, "Sign must be one of +/-"
|
|
v = Cq.Vector(x, y, z) * sign
|
|
else:
|
|
v = Cq.Vector(direction)
|
|
edge = Cq.Edge.makeLine(v * (-1), v)
|
|
self.eachpoint(edge.moved, useLocalCoordinates=True).tag(tag)
|
|
|
|
Cq.Workplane.tagPlane = tagPlane
|