cadquery
Sketch
Workplane
Assembly

Assembly.add()

The Assembly.add() method in cadquery is used to add a component or a list of components to an assembly. This method can be used to build complex 3D models by combining multiple individual components together.

Syntax

Assembly.add(components)

Parameters

  • components - A single component or a list of components.

Returns

  • The updated assembly containing the added components.

Description

The components parameter can be a single component or a list of components. A component can be created using any of the methods in cadquery, such as Box(), Cylinder(), etc.

When the Assembly.add() method is called, the components are added to the assembly according to their relative positions and orientations. The components can be translated, rotated, or scaled before being added to the assembly.

Examples

To add a single component to an assembly:

import cadquery as cq

# Create the component
component = cq.Box(1, 1, 1)

# Create the assembly
assembly = cq.Assembly()

# Add the component to the assembly
assembly.add(component)

To add multiple components to an assembly:

import cadquery as cq

# Create the components
component1 = cq.Box(1, 1, 1)
component2 = cq.Cylinder(1, 1)

# Create the assembly
assembly = cq.Assembly()

# Add the components to the assembly
assembly.add([component1, component2])

To translate a component before adding it to an assembly:

import cadquery as cq

# Create the component
component = cq.Box(1, 1, 1).translate((1, 0, 0))

# Create the assembly
assembly = cq.Assembly()

# Add the component to the assembly
assembly.add(component)

To rotate a component before adding it to an assembly:

import cadquery as cq

# Create the component
component = cq.Box(1, 1, 1).rotate((0, 0, 1), 45)

# Create the assembly
assembly = cq.Assembly()

# Add the component to the assembly
assembly.add(component)

To scale a component before adding it to an assembly:

import cadquery as cq

# Create the component
component = cq.Box(1, 1, 1).scale(2)

# Create the assembly
assembly = cq.Assembly()

# Add the component to the assembly
assembly.add(component)

Conclusion

The Assembly.add() method in cadquery provides a simple and powerful way to add components to an assembly. This method can be used to build complex 3D models from simple building blocks.