Skip to main content

CadQuery object filtering framework

cq-filter adds a few new workplane methods that take a function argument of type f: Callable[[CQObject], bool]:

  • filter(f): filters Workplane objects
  • sort(f): orders Workplane objects
  • group(f): groups Workplane objects
  • last: selects newly created faces
  • toWires: select wires from selected faces

Additionally, it adds subscription support to the Workplane, allowing selection of objects quickly.

Rationale

Manipulating object selections in cadquery isn't currently possible without breaking out of the fluent API.

Using filter

Following example filters all faces with an Area of more than 100

wp = (
    wp
    .faces(">Z")
    .filter(lambda face: face.Area() > 100)
)

⚠️ values in cq/occt are often not as exact as you'd expect. For example you might expect a certain face to have an area of exactly 100 and be included when you filter the area against >= 100, but upon closer inspection it turns out the area is actually just slightly below 100 (99.999999997). Consider rounding to some sane precision, like round(face.Area(), 4)

Using sort and subscription

Following example sorts all faces by area and selects the three biggest ones

wp = (
    wp
    .faces(">Z")
    .sort(lambda face: face.Area())[-3:]
)

Using group and clustering

Select the smallest faces that are within 10 units of each other

wp = (
    wp
    .faces(">Z")
    .group(Cluster(lambda face: face.Area(), tol=10)[0])
)
  • ⚠️group() call will not yet select new objects, but it will create a new workplane object. Selection should be done immediatelly after the grouping. Grouping data will be erased by next manipulation of workplane.

  • selecting a range of groups ([0:2]) works as expected

  • Cluster() defaults to a tolerance of 1e-4

Using last to select newly created faces

A call to .last(everything=False) attempts to select newly created faces. When everything = False it will only select faces that share all their edges with other new faces. In other words: probably the face you'd want to focus on after some operation like extrude, cut or revolve will be selected.

Supplying everything = True will select all faces that are new.

from cq_filter import Workplane

wp = (
    Workplane()
    .rect(5, 5)
    .extrude(2)
    .last()
    .workplane()
)
  • ⚠️ last will not select faces that were modified

Usage

You may want to create your own workplane class if you have multiple mixins

from cq_filter import CQFilterMixin

class Workplane(CQFilterMixin, cq.Workplane):
   pass

If you don't have multiple mixins, then the above class can also be directly imported

from cq_filter import Workplane

Metadata

Release files for cq-filter 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cq-filter 0.0.3
File Size Uploaded Provenance Actions
cq-filter-0.0.3.tar.gz 13.0 kB Without provenance Details for cq-filter-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cq-filter 0.0.3
File Interpreter ABI Platform Actions
cq_filter-0.0.3-py3-none-any.whl Python 3 none any Details for cq_filter-0.0.3-py3-none-any.whl

Total release size: 23.9 kB

Release files / cq-filter-0.0.3.tar.gz

Download URL cq-filter-0.0.3.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1d7ee331b190fd1cf7b2ee5c4884105cf3908f76db083620b7d3d0b0a2b8f507
BLAKE2b-256 checksum
How to use checksums
361ff99704b929a5464363f6f858d577ff45767ddda2df1ee1b60f49ffca2f17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / cq_filter-0.0.3-py3-none-any.whl

Download URL cq_filter-0.0.3-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27d6fcf188e0379f7dcd72570cac6565561ad78375b94c7195d57bb175f0933a
BLAKE2b-256 checksum
How to use checksums
c0ccb89b7e9328b13efe4785301b0088b596cd662e1c7a0b8fbb16924ed9e32c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.3

Security for cq-filter 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page