Files
2026-09-24 10:40:57 +08:00

29 lines
932 B
Python

from build123d import Circle, Plane, Pos, extrude
def validate(context, target, params):
errors = []
if target is None:
errors.append("NO_TARGET: hole_simple 需要一个实体作为输入")
return errors
bbox = target.bounding_box()
x, y = params["x"], params["y"]
if not (bbox.min.X <= x <= bbox.max.X and bbox.min.Y <= y <= bbox.max.Y):
errors.append(
f"HOLE_OUT_OF_BOUNDS: 孔位置({x},{y})超出零件顶面范围"
f"(X[{bbox.min.X:.2f},{bbox.max.X:.2f}] Y[{bbox.min.Y:.2f},{bbox.max.Y:.2f}])"
)
return errors
def run(context, target, params):
bbox = target.bounding_box()
top_z = bbox.max.Z
depth = params["depth"]
plane = Plane.XY.offset(top_z - depth)
hole_sketch = plane * (Pos(params["x"], params["y"], 0) * Circle(params["diameter"] / 2))
cutter = extrude(hole_sketch, amount=depth)
return target - cutter