23 lines
699 B
Python
23 lines
699 B
Python
from build123d import FilletPolyline, Plane, Polygon, Pos, make_face
|
|
|
|
|
|
def validate(context, target, params):
|
|
errors = []
|
|
if len(params.get("points", [])) < 3:
|
|
errors.append("TOO_FEW_POINTS: 至少需要3个点才能构成一个封闭多边形")
|
|
return errors
|
|
|
|
|
|
def run(context, target, params):
|
|
points = [tuple(p) for p in params["points"]]
|
|
radius = params.get("corner_radius", 0)
|
|
|
|
if radius and radius > 0:
|
|
path = FilletPolyline(*points, radius=radius, close=True)
|
|
sketch = make_face(path.edges())
|
|
else:
|
|
sketch = Polygon(*points)
|
|
|
|
positioned = Pos(params["x_offset"], params["y_offset"], 0) * sketch
|
|
return Plane.XY * positioned
|