41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
from bd_warehouse.thread import IsoThread
|
|
|
|
_MIN_FACES_FOR_REAL_THREAD = 40
|
|
|
|
|
|
def validate(context, target, params):
|
|
errors = []
|
|
if target is None:
|
|
errors.append("NO_TARGET: hole_tapped 需要一个实体作为输入")
|
|
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})超出零件顶面范围")
|
|
return errors
|
|
|
|
|
|
def run(context, target, params):
|
|
bbox = target.bounding_box()
|
|
top_z = bbox.max.Z
|
|
depth = params["depth"]
|
|
x, y = params["x"], params["y"]
|
|
|
|
cutter = IsoThread(
|
|
major_diameter=params["major_diameter"],
|
|
pitch=params["pitch"],
|
|
length=depth,
|
|
external=False,
|
|
hand=params["hand"],
|
|
simple=False, # 禁止简化模式:跟标准件一样,攻丝孔必须是真实牙型,不是光孔
|
|
)
|
|
|
|
if len(cutter.faces()) < _MIN_FACES_FOR_REAL_THREAD:
|
|
raise RuntimeError(
|
|
f"IsoThread(internal) 生成结果只有 {len(cutter.faces())} 个面,疑似退化成了光孔,已阻止导出"
|
|
)
|
|
|
|
cutter = cutter.translate((x, y, top_z - depth))
|
|
return target - cutter
|