cadquery
Sketch
Workplane
Assembly

TypeSelector()

The TypeSelector() class in CadQuery is a type of selector that allows you to select specific types of objects from a model. This is particularly useful when you need to access certain features or components of a model for further manipulation.

Syntax

TypeSelector(type)

Parameters

  • type (str or list or tuple): The type or types of objects for which you wish to select.

Return Value

A Selector object that contains the selected objects.

Examples

import cadquery as cq

# Create a box with two holes
box = cq.Workplane().box(10, 10, 10).faces(">Z").workplane().\
    circle(3).extrude(2).faces(">Z").workplane().circle(2).extrude(2)
    
# Select all the circles in the model
circles = box.faces(">Z").wires().circles().vals()
import cadquery as cq

# Create a box with two holes
box = cq.Workplane().box(10, 10, 10).faces(">Z").workplane().\
    circle(3).extrude(2).faces(">Z").workplane().circle(2).extrude(2)
    
# Select all the edges in the model
edges = box.edges().vals()

# Select all the faces in the model
faces = box.faces().vals()

In the above examples, the TypeSelector() method is used to select specific types of objects from a 3D model (box). In the first example, circles selects all circles in the model, while in the second example, edges selects all the edges in the model and faces selects all the faces in the model.

Conclusion

The TypeSelector() class in CadQuery is a useful feature for selecting specific types of objects from a 3D model for further manipulation. By passing the desired type to the TypeSelector() method, you can easily select and access these objects in your code.