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

Method each

cadquery/sketch.py:499–552  ·  view source on GitHub ↗

Apply a callback on all applicable entities.

(
        self: T,
        callback: Callable[[Location], Union[Face, "Sketch", Compound]],
        mode: Modes = "a",
        tag: Optional[str] = None,
        ignore_selection: bool = False,
    )

Source from the content-addressed store, hash-verified

497 return self
498
499 def each(
500 self: T,
501 callback: Callable[[Location], Union[Face, "Sketch", Compound]],
502 mode: Modes = "a",
503 tag: Optional[str] = None,
504 ignore_selection: bool = False,
505 ) -> T:
506 """
507 Apply a callback on all applicable entities.
508 """
509
510 res: List[Face] = []
511 locs: List[Location] = []
512
513 if self._selection and not ignore_selection:
514 for el in self._selection:
515 if isinstance(el, Location):
516 loc = el
517 else:
518 loc = Location(el.Center())
519
520 locs.append(loc)
521
522 else:
523 locs.append(Location())
524
525 for loc in locs:
526 tmp = callback(loc)
527
528 if isinstance(tmp, Sketch):
529 res.extend(tmp._faces.Faces())
530 elif isinstance(tmp, Compound):
531 res.extend(tmp.Faces())
532 else:
533 res.append(tmp)
534
535 if tag:
536 self._tag(res, tag)
537
538 if mode == "a":
539 self._faces = self._faces.fuse(*res)
540 elif mode == "s":
541 self._faces = self._faces.cut(*res)
542 elif mode == "i":
543 self._faces = self._faces.intersect(*res)
544 elif mode == "r":
545 self._faces = Compound.makeCompound(res)
546 elif mode == "c":
547 if not tag:
548 raise ValueError("No tag specified - the geometry will be unreachable")
549 else:
550 raise ValueError(f"Invalid mode: {mode}")
551
552 return self
553
554 # modifiers
555 def hull(self: T, mode: Modes = "a", tag: Optional[str] = None) -> T:

Callers 4

faceMethod · 0.95
rectMethod · 0.95
circleMethod · 0.95
ellipseMethod · 0.95

Calls 10

_tagMethod · 0.95
LocationClass · 0.85
appendMethod · 0.80
extendMethod · 0.80
makeCompoundMethod · 0.80
CenterMethod · 0.45
FacesMethod · 0.45
fuseMethod · 0.45
cutMethod · 0.45
intersectMethod · 0.45

Tested by

no test coverage detected