cadquery
Sketch
Workplane
Assembly

Assembly.save()

The Assembly.save() method is used to save the current state of an assembly as an STL or STEP file. This method can be called on a cq.Assembly object, which is used to define the hierarchical structure of an assembly.

Syntax

my_assembly.save(filepath, file_type="STEP")

Parameters

  • filepath (string): The file path to save the file to, including the file name and extension.
  • file_type (string, optional): The file type to save the assembly as. Valid options are "STEP" (default) or "STL".

Example Usage

import cadquery as cq

# Define an assembly hierarchy
box1 = cq.Workplane("XY").box(10, 10, 10)
box2 = cq.Workplane("XY").box(5, 5, 5).translate((5, 5, 5))
assembly = cq.Assembly().add(box1).add(box2)

# Save the assembly as an STL file
assembly.save("assembly.stl", file_type="STL")

# Save the assembly as a STEP file
assembly.save("assembly.step")

In this example, an assembly hierarchy is defined using cq.Assembly() and two cq.Workplane().box() objects. The assembly is then saved as both an STL and STEP file using the Assembly.save() method with the appropriate file type parameter.

Notes

  • The Assembly.save() method will save the current state of the assembly object, including any modifications made to its child objects.
  • The file extension is used to determine the file type to be saved. If an invalid file extension is used, the save method will raise a ValueError.