MCPcopy
hub / github.com/CadQuery/cadquery / AreaNthSelector

Class AreaNthSelector

cadquery/selectors.py:472–537  ·  view source on GitHub ↗

Selects the object(s) with Nth area Applicability: - Faces, Shells, Solids - Shape.Area() is used to compute area - closed planar Wires - a temporary face is created to compute area Will ignore non-planar or non-closed wires. Among other things can be used to sele

Source from the content-addressed store, hash-verified

470
471
472class AreaNthSelector(_NthSelector):
473 """
474 Selects the object(s) with Nth area
475
476 Applicability:
477 - Faces, Shells, Solids - Shape.Area() is used to compute area
478 - closed planar Wires - a temporary face is created to compute area
479
480 Will ignore non-planar or non-closed wires.
481
482 Among other things can be used to select one of
483 the nested coplanar wires or faces.
484
485 For example to create a fillet on a shank::
486
487 result = (
488 cq.Workplane("XY")
489 .circle(5)
490 .extrude(2)
491 .circle(2)
492 .extrude(10)
493 .faces(">Z[-2]")
494 .wires(AreaNthSelector(0))
495 .fillet(2)
496 )
497
498 Or to create a lip on a case seam::
499
500 result = (
501 cq.Workplane("XY")
502 .rect(20, 20)
503 .extrude(10)
504 .edges("|Z or <Z")
505 .fillet(2)
506 .faces(">Z")
507 .shell(2)
508 .faces(">Z")
509 .wires(AreaNthSelector(-1))
510 .toPending()
511 .workplane()
512 .offset2D(-1)
513 .extrude(1)
514 .faces(">Z[-2]")
515 .wires(AreaNthSelector(0))
516 .toPending()
517 .workplane()
518 .cutBlind(2)
519 )
520 """
521
522 def key(self, obj: Shape) -> float:
523 if obj.ShapeType() in ("Face", "Shell", "Solid"):
524 return obj.Area()
525 elif obj.ShapeType() == "Wire":
526 try:
527 from cadquery.occ_impl.shapes import Face, Wire
528
529 return abs(Face.makeFromWires(cast(Wire, obj)).Area())

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected