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

Method each

cadquery/cq.py:2379–2436  ·  view source on GitHub ↗

Runs the provided function on each value in the stack, and collects the return values into a new CQ object. Special note: a newly created workplane always has its center point as its only stack item :param callBackFunction: the function to call for each item on the

(
        self: T,
        callback: Callable[[CQObject], Shape],
        useLocalCoordinates: bool = False,
        combine: CombineMode = True,
        clean: bool = True,
    )

Source from the content-addressed store, hash-verified

2377 return self.newObject(others + [w])
2378
2379 def each(
2380 self: T,
2381 callback: Callable[[CQObject], Shape],
2382 useLocalCoordinates: bool = False,
2383 combine: CombineMode = True,
2384 clean: bool = True,
2385 ) -> T:
2386 """
2387 Runs the provided function on each value in the stack, and collects the return values into
2388 a new CQ object.
2389
2390 Special note: a newly created workplane always has its center point as its only stack item
2391
2392 :param callBackFunction: the function to call for each item on the current stack.
2393 :param useLocalCoordinates: should values be converted from local coordinates first?
2394 :param combine: True or "a" to combine the resulting solid with parent solids if found,
2395 "cut" or "s" to remove the resulting solid from the parent solids if found.
2396 False to keep the resulting solid separated from the parent solids.
2397 :param clean: call :meth:`clean` afterwards to have a clean shape
2398
2399
2400 The callback function must accept one argument, which is the item on the stack, and return
2401 one object, which is collected. If the function returns None, nothing is added to the stack.
2402 The object passed into the callBackFunction is potentially transformed to local coordinates,
2403 if useLocalCoordinates is true
2404
2405 useLocalCoordinates is very useful for plugin developers.
2406
2407 If false, the callback function is assumed to be working in global coordinates. Objects
2408 created are added as-is, and objects passed into the function are sent in using global
2409 coordinates
2410
2411 If true, the calling function is assumed to be working in local coordinates. Objects are
2412 transformed to local coordinates before they are passed into the callback method, and result
2413 objects are transformed to global coordinates after they are returned.
2414
2415 This allows plugin developers to create objects in local coordinates, without worrying
2416 about the fact that the working plane is different than the global coordinate system.
2417
2418
2419 TODO: wrapper object for Wire will clean up forConstruction flag everywhere
2420 """
2421 results = []
2422 for obj in self.objects:
2423
2424 if useLocalCoordinates:
2425 # TODO: this needs to work for all types of objects, not just vectors!
2426 r = callback(self.plane.toLocalCoords(obj))
2427 r = r.transformShape(self.plane.rG)
2428 else:
2429 r = callback(obj)
2430
2431 if isinstance(r, Wire):
2432 if not r.forConstruction:
2433 self._addPendingWire(r)
2434 results.append(r)
2435
2436 return self._combineWithBase(results, combine, clean)

Callers 3

rotateAboutCenterMethod · 0.95
test_eachFunction · 0.45
vtk.jsFile · 0.45

Calls 5

_addPendingWireMethod · 0.95
_combineWithBaseMethod · 0.95
toLocalCoordsMethod · 0.80
transformShapeMethod · 0.80
appendMethod · 0.80

Tested by 1

test_eachFunction · 0.36