cadquery
Sketch
Workplane
Assembly

BoxSelector()

The BoxSelector() is a selection tool in the CadQuery library that allows the user to select a group of objects within a certain 3D space.

Usage

box = cq.BoxSelector(xmin, ymin, zmin, xmax, ymax, zmax)
result = box.select(objects)

Parameters

  • xmin (float): minimum x-coordinate of the 3D selection box
  • ymin (float): minimum y-coordinate of the 3D selection box
  • zmin (float): minimum z-coordinate of the 3D selection box
  • xmax (float): maximum x-coordinate of the 3D selection box
  • ymax (float): maximum y-coordinate of the 3D selection box
  • zmax (float): maximum z-coordinate of the 3D selection box
  • objects (list): a list of CadQuery objects to be selected from

Returns

  • result (list): a list of CadQuery objects within the selection box

Example

import cadquery as cq

# create some objects
box1 = cq.Workplane("XY").rect(5,5).extrude(2)
box2 = cq.Workplane("XY").rect(10,10).extrude(2)

# combine them into a compound object
compound = box1.union(box2.translate((5,5,0)))

# create the selector
selector = cq.BoxSelector(0,0,0,7,7,2)

# select the objects
result = selector.select([compound])

# display the result
show_object(result)

This code will create two boxes, combine them into a compound object, and then use the BoxSelector() to select only the portion of the compound object within a 7x7x2 box starting at the origin. The resulting object will be displayed using the show_object() function.