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

New section "Iterating Over Compounds" to Assembly documentation. #713

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/assemblies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,28 @@ adds the following attributes to :class:`~topology.Shape`:

.. _pack:

************************
Iterating Over Compounds
************************

As Compounds are containers for shapes, Build123 can iterate over these as required.
jdegenstein marked this conversation as resolved.
Show resolved Hide resolved
Complex nested assemblies (compounds within compounds) do not need to be looped over with recursive functions.
In the example below, the variable total_volume holds the sum of all the volumes in each solid in an assembly.
Compare this to assembly3_volume which only results in the volume of the top level part.

.. code:: python

# [import]
from build123d import *
from ocp_vscode import *

# Each assembly has a box and the previous assembly.
assembly1 = Compound(label='Assembly1', children=[Box(1, 1, 1),])
assembly2 = Compound(label='Assembly2', children=[assembly1, Box(1, 1, 1)])
assembly3 = Compound(label='Assembly3', children=[assembly2, Box(1, 1, 1)])
total_volume = sum([part.volume for part in assembly3.solids()]) # 3
assembly3_volume = assembly3.volume # 1

******
pack
******
Expand Down
Loading