34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from build123d import Circle, Plane, Pos, extrude
|
|
|
|
|
|
def validate(context, target, params):
|
|
errors = []
|
|
if target is None:
|
|
errors.append("NO_TARGET: hole_through_axis 需要一个实体作为输入")
|
|
return errors
|
|
|
|
|
|
def run(context, target, params):
|
|
bbox = target.bounding_box()
|
|
axis = params["axis"]
|
|
r = params["diameter"] / 2
|
|
o1, o2 = params["offset1"], params["offset2"]
|
|
|
|
if axis == "X":
|
|
length = bbox.size.X + 20
|
|
start_x = bbox.min.X - 10
|
|
plane = Plane(origin=(start_x, o1, o2), x_dir=(0, 1, 0), z_dir=(1, 0, 0))
|
|
cutter = extrude(plane * Circle(r), amount=length)
|
|
elif axis == "Y":
|
|
length = bbox.size.Y + 20
|
|
start_y = bbox.min.Y - 10
|
|
plane = Plane(origin=(o1, start_y, o2), x_dir=(1, 0, 0), z_dir=(0, 1, 0))
|
|
cutter = extrude(plane * Circle(r), amount=length)
|
|
else: # Z
|
|
length = bbox.size.Z + 20
|
|
start_z = bbox.min.Z - 10
|
|
plane = Plane.XY.offset(start_z)
|
|
cutter = extrude(plane * (Pos(o1, o2, 0) * Circle(r)), amount=length)
|
|
|
|
return target - cutter
|