Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a section to the docs on sort_by/filter_by/group_by shape property #886

Open
gumyr opened this issue Jan 29, 2025 · 0 comments
Open
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@gumyr
Copy link
Owner

gumyr commented Jan 29, 2025

As a replacement for the SortBy functionality of the ShapeList, one can use class properties, like:

shape.edges().filter_by(Edge.is_interior)

or

from itertools import product

from build123d import Box, ShapeList, Solid, Vertex
from ocp_vscode import ColorMap, show

boxes = ShapeList(
    Box(1, 1, 1).scale(0.75 if (i, j) == (1, 2) else 0.25).translate((i, j, 0))
    for i, j in product(range(-5, 6), repeat=2)
)

# sort by distance to origin
boxes = boxes.sort_by(Vertex().distance)
show(*boxes, colors=ColorMap.listed(len(boxes)))

and

# sort by distance to largest box
boxes = boxes.sort_by(boxes.sort_by(Solid.volume).last.distance)
show(*boxes, colors=ColorMap.listed(len(boxes)))

Image

@gumyr gumyr added documentation Improvements or additions to documentation enhancement New feature or request labels Jan 29, 2025
@gumyr gumyr added this to the Gating Release 1.0.0 milestone Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant