31 lines
934 B
Python
31 lines
934 B
Python
from build123d import Axis
|
|
from build123d import offset as _offset
|
|
|
|
|
|
def validate(context, target, params):
|
|
errors = []
|
|
if target is None:
|
|
errors.append("NO_TARGET: shell 需要一个实体作为输入")
|
|
return errors
|
|
|
|
bbox = target.bounding_box()
|
|
min_dim = min(bbox.size.X, bbox.size.Y, bbox.size.Z)
|
|
if params["thickness"] >= min_dim / 2:
|
|
errors.append(
|
|
f"THICKNESS_TOO_LARGE: 壁厚{params['thickness']}mm过大,应小于{min_dim / 2:.2f}mm"
|
|
)
|
|
return errors
|
|
|
|
|
|
def run(context, target, params):
|
|
selector = params["opening_selector"]
|
|
faces = target.faces()
|
|
|
|
openings = []
|
|
if selector in ("top", "top_and_bottom"):
|
|
openings.append(faces.sort_by(Axis.Z)[-1])
|
|
if selector in ("bottom", "top_and_bottom"):
|
|
openings.append(faces.sort_by(Axis.Z)[0])
|
|
|
|
return _offset(target, amount=-params["thickness"], openings=openings or None)
|