Name | cq-filter JSON |
Version |
0.0.3
JSON |
| download |
home_page | |
Summary | Cadquery object filtering framework |
upload_time | 2023-05-20 20:51:13 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.10 |
license | Apache License 2.0 |
keywords |
cadquery
filter
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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
```python
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
```python
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
```python
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.
```python
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
```python
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
```python
from cq_filter import Workplane
```
Raw data
{
"_id": null,
"home_page": "",
"name": "cq-filter",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": "",
"keywords": "cadquery,filter",
"author": "",
"author_email": "Matti Eiden <snaipperi@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/36/1f/f99704b929a5464363f6f858d577ff45767ddda2df1ee1b60f49ffca2f17/cq-filter-0.0.3.tar.gz",
"platform": null,
"description": "# CadQuery object filtering framework\n\n\ncq-filter adds a few new workplane methods that take a function argument\nof type `f: Callable[[CQObject], bool]`:\n\n* `filter(f)`: filters Workplane objects\n* `sort(f)`: orders Workplane objects\n* `group(f)`: groups Workplane objects\n* `last`: selects newly created faces\n* `toWires`: select wires from selected faces\n\nAdditionally, it adds subscription support to the Workplane, allowing \nselection of objects quickly.\n\n## Rationale\n\nManipulating object selections in cadquery isn't currently possible without breaking out of the fluent API.\n\n\n## Using filter\n\nFollowing example filters all faces with an Area of more than 100\n\n```python\nwp = (\n wp\n .faces(\">Z\")\n .filter(lambda face: face.Area() > 100)\n)\n```\n\n\u26a0\ufe0f values in cq/occt are often not as exact as you'd expect. For example you might expect a certain \nface to have an area of exactly 100 and be included when you filter the area against `>= 100`, but upon\ncloser inspection it turns out the area is actually just slightly below 100 (99.999999997). Consider rounding to some\nsane precision, like `round(face.Area(), 4)`\n\n## Using sort and subscription\n\nFollowing example sorts all faces by area and selects the three biggest ones\n\n```python\nwp = (\n wp\n .faces(\">Z\")\n .sort(lambda face: face.Area())[-3:]\n)\n```\n\n## Using group and clustering\n\n\nSelect the smallest faces that are within 10 units of each other\n\n```python\nwp = (\n wp\n .faces(\">Z\")\n .group(Cluster(lambda face: face.Area(), tol=10)[0])\n)\n```\n\n* \u26a0\ufe0f`group()` call will not yet select new objects, but it will create a new workplane object.\nSelection should be done immediatelly after the grouping. Grouping data will be erased by \nnext manipulation of workplane.\n\n* selecting a range of groups (`[0:2]`) works as expected\n\n* Cluster() defaults to a tolerance of `1e-4`\n\n## Using `last` to select newly created faces\n\nA call to `.last(everything=False)` attempts to select newly created faces. When `everything = False` it will only\nselect faces that share all their edges with other new faces. In other words: probably the face you'd want to focus on\nafter some operation like extrude, cut or revolve will be selected. \n\nSupplying `everything = True` will select all faces that are new.\n\n```python\nfrom cq_filter import Workplane\n\nwp = (\n Workplane()\n .rect(5, 5)\n .extrude(2)\n .last()\n .workplane()\n)\n```\n\n* \u26a0\ufe0f `last` will not select faces that were modified \n\n\n## Usage \n\nYou may want to create your own workplane class if you have multiple mixins\n\n```python \nfrom cq_filter import CQFilterMixin\n\nclass Workplane(CQFilterMixin, cq.Workplane):\n pass\n```\n\nIf you don't have multiple mixins, then the above class can also be directly imported \n\n```python \nfrom cq_filter import Workplane\n```\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Cadquery object filtering framework",
"version": "0.0.3",
"project_urls": {
"Bug Tracker": "https://github.com/voneiden/cq-filter/issues/",
"Documentation": "https://github.com/voneiden/cq-filter/",
"Source Code": "https://github.com/voneiden/cq-filter/"
},
"split_keywords": [
"cadquery",
"filter"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c0ccb89b7e9328b13efe4785301b0088b596cd662e1c7a0b8fbb16924ed9e32c",
"md5": "fb661a12817f8b4899ad41a3fbbc186f",
"sha256": "27d6fcf188e0379f7dcd72570cac6565561ad78375b94c7195d57bb175f0933a"
},
"downloads": -1,
"filename": "cq_filter-0.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fb661a12817f8b4899ad41a3fbbc186f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 10907,
"upload_time": "2023-05-20T20:51:12",
"upload_time_iso_8601": "2023-05-20T20:51:12.597892Z",
"url": "https://files.pythonhosted.org/packages/c0/cc/b89b7e9328b13efe4785301b0088b596cd662e1c7a0b8fbb16924ed9e32c/cq_filter-0.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "361ff99704b929a5464363f6f858d577ff45767ddda2df1ee1b60f49ffca2f17",
"md5": "6bb8678b9dc399eb1d3ec16b2280882b",
"sha256": "1d7ee331b190fd1cf7b2ee5c4884105cf3908f76db083620b7d3d0b0a2b8f507"
},
"downloads": -1,
"filename": "cq-filter-0.0.3.tar.gz",
"has_sig": false,
"md5_digest": "6bb8678b9dc399eb1d3ec16b2280882b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 12962,
"upload_time": "2023-05-20T20:51:13",
"upload_time_iso_8601": "2023-05-20T20:51:13.933186Z",
"url": "https://files.pythonhosted.org/packages/36/1f/f99704b929a5464363f6f858d577ff45767ddda2df1ee1b60f49ffca2f17/cq-filter-0.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-20 20:51:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "voneiden",
"github_project": "cq-filter",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "cq-filter"
}