cadquery
Sketch
Workplane
Assembly

Assembly()

The Assembly() method in cadquery allows the creation of complex 3D assemblies by merging multiple parts together.

Syntax

Assembly(name=None, move=None, rotate=None)

Parameters

  • name (optional): A string representing the name of the assembly. If not specified, a default name will be used.
  • move (optional): A tuple representing the displacement of the assembly in (x, y, z) directions. If not specified, the assembly will be at the origin.
  • rotate (optional): A tuple representing the rotation angles around (x, y, z) axes in degrees. If not specified, the assembly will not be rotated.

Return value

A new Assembly object.

Examples

Example 1: Simple assembly

import cadquery as cq

# Create two cubes
c1 = cq.Workplane().box(1, 1, 1)
c2 = cq.Workplane().box(1, 1, 1)

# Create an assembly and add the cubes to it
assembly = cq.Assembly()
assembly.add(c1)
assembly.add(c2)

# Export the assembly as an STL file
cq.exporters.export(assembly, "assembly.stl")

Example 2: Moving and rotating an assembly

import cadquery as cq

# Create two cubes
c1 = cq.Workplane().box(1, 1, 1)
c2 = cq.Workplane().box(1, 1, 1)

# Create an assembly and add the cubes to it
assembly = cq.Assembly()
assembly.add(c1)
assembly.add(c2)

# Move the assembly 5 units in the x direction and rotate it
assembly = assembly.rotate((0, 0, 0), (0, 0, 90))
assembly = assembly.translate((5, 0, 0))

# Export the assembly as an STL file
cq.exporters.export(assembly, "assembly.stl")

Notes

  • Assembly objects are mutable, so you can add or remove parts from them.
  • When adding parts to an assembly, they become child objects of the assembly and their coordinates are transformed accordingly.