CadQuery Class Reference

This page documents all of the methods and functions of the CadQuery classes, organized alphabatically.

See also

For a listing organized by functional area, see the CadQuery API Reference

Core Classes

CQ(obj) Provides enhanced functionality for a wrapped CAD primitive.
Plane(origin, xDir, normal) A 2d coordinate system in space, with the x-y axes on the a plane, and a particular point as the origin.
Workplane(inPlane[, origin, obj]) Defines a coordinate system in space, in which 2-d coordinates can be used.

Selectors

NearestToPointSelector(pnt) Selects object nearest the provided point.
ParallelDirSelector(vector[, tolerance]) Selects objects parallel with the provided direction
DirectionSelector(vector[, tolerance]) Selects objects aligned with the provided direction
PerpendicularDirSelector(vector[, tolerance]) Selects objects perpendicular with the provided direction
TypeSelector(typeString) Selects objects of the prescribed topological type.
DirectionMinMaxSelector(vector[, directionMax]) Selects objects closest or farthest in the specified direction
StringSyntaxSelector(selectorString) Filter lists objects using a simple string syntax.

Classes

class cadfile.cadutils.cadquery.CQ(obj)[source]

Provides enhanced functionality for a wrapped CAD primitive.

Examples include feature selection, feature creation, 2d drawing using work planes, and 3d opertations like fillets, shells, and splitting

Future Enhancements:
2D:
polar array– subdivide circle by angle to create a list of points midpoint – subdivide edges to create points at midpoints 2d fillet/arc? Or would it be tangent arc between lines?
Selectors:
midpoint selector intersection selector nth closest furthest selector: such as >Z[2] means 2nd maximum along z rotated coordinate systems ( so that selectors can be used in other directions
3D:
create cylinder create torus create wedge create sphere revolve through angle to create solid sheet metal folding?
Transformations:
rotate creating copy translate creating copy
add(obj)[source]

adds an object or a list of objects to the stack

Parameters:obj (a CQ object, CAD primitive, or list of CAD primitives) – an object to add
Returns:a CQ object with the requested operation performed

If an CQ object, the values of that object’s stack are added. If a list of cad primitives, they are all added. If a single CAD primitive it is added

Used in rare cases when you need to combine the results of several CQ results into a single CQ object. Shelling is one common example

all()[source]

Return a list of all CQ objects on the stack.

useful when you need to operate on the elements individually.

Contrast with vals, which returns the underlying objects for all of the items on the stack

combineSolids(otherCQToCombine=None)[source]

!!!DEPRECATED!!! use union() Combines all solids on the current stack, and any context object, together into a single object.

After the operation, the returned solid is also the context solid.

Parameters:otherCQToCombine – another cadquery to combine.
Returns:a cQ object with the resulting combined solid on the stack.

Most of the time, both objects will contain a single solid, which is combined and returned on the stack of the new object.

compounds(selector=None)[source]

Select compounds on the stack, optionally filtering the selection. If there are multiple objects on the stack, they are collected and a list of all the distinct compounds is returned.

Parameters:selector (None, a Selector object, or a string selector expression.) – A selector
Returns:a CQ object whos stack contains all of the distinct solids of all objects on the current stack, filtered by the provided selector.

A compound contains multiple CAD primitives that resulted from a single operation, such as a union, cut, split, or fillet. Compounds can contain multiple edges, wires, or solids.

See more about selectors HERE

edges(selector=None)[source]

Select the edges of objects on the stack, optionally filtering the selection. If there are multiple objects on the stack, the edges of all objects are collected and a list of all the distinct edges is returned.

Parameters:selector (None, a Selector object, or a string selector expression.) – A selector
Returns:a CQ object whos stack contains all of the distinct edges of all objects on the current stack, filtered by the provided selector.

If there are no edges for any objects on the current stack, an empty CQ object is returned

The typical use is to select the edges of a single object on the stack. For example:

CQ(aCube).faces("+Z").edges().size()

returns 4, because a cube has one face with a normal in the +Z direction. Similarly:

CQ(aCube).edges().size()

returns 12, because a cube has a total of 12 edges, And:

CQ(aCube).edges("|Z").size()

returns 4, because a cube has 4 edges parallel to the z direction

See more about selectors HERE

end()[source]

Return the parent of this CQ element :rtype: a CQ object :raises: ValueError if there are no more parents in the chain.

For example:

CQ(obj).faces("+Z").vertices().end()

will return the same as:

CQ(obj).faces("+Z")
exportSvg(fileName)[source]

Exports the first item on the stack as an SVG file

For testing purposes mainly.

Parameters:fileName (String, absolute path to the file) – the filename to export
faces(selector=None)[source]

Select the faces of objects on the stack, optionally filtering the selection. If there are multiple objects on the stack, the faces of all objects are collected and a list of all the distinct faces is returned.

Parameters:selector (None, a Selector object, or a string selector expression.) – A selector
Returns:a CQ object whos stack contains all of the distinct faces of all objects on the current stack, filtered by the provided selector.

If there are no vertices for any objects on the current stack, an empty CQ object is returned

The typical use is to select the faces of a single object on the stack. For example:

CQ(aCube).faces("+Z").size()

returns 1, because a cube has one face with a normal in the +Z direction. Similarly:

CQ(aCube).faces().size()

returns 6, because a cube has a total of 6 faces, And:

CQ(aCube).faces("|Z").size()

returns 2, because a cube has 2 faces having normals parallel to the z direction

See more about selectors HERE

fillet(radius)[source]

Fillets a solid on the selected edges.

The edges on the stack are filleted. The solid to which the edges belong must be in the parent chain of the selected edges.

Parameters:radius (positive float) – the radius of the fillet, must be > zero
Raises :ValueError if at least one edge is not selected
Raises :ValueError if the solid containing the edge is not in the chain
Returns:cq object with the resulting solid selected.

This example will create a unit cube, with the top edges filleted:

s = Workplane().box(1,1,1).faces("+Z").edges().fillet(0.1)
findSolid(searchStack=True, searchParents=True)[source]

Finds the first solid object in the chain, searching from the current node backwards through parents until one is found.

Parameters:
  • searchStack – should objects on the stack be searched first.
  • searchParents – should parents be searched?
Raises :

ValueError if no solid is found in the current object or its parents, and errorOnEmpty is True

This function is very important for chains that are modifying a single parent object, most often a solid.

Most of the time, a chain defines or selects a solid, and then modifies it using workplanes or other operations.

Plugin Developers should make use of this method to find the solid that should be modified, if the plugin implements a unary operation, or if the operation will automatically merge its results with an object already on the stack.

first()[source]

Return the first item on the stack :returns: the first item on the stack. :rtype: a CQ object

item(i)[source]

Return the ith item on the stack. :rtype: a CQ object

last()[source]

Return the last item on the stack. :rtype: a CQ object

newObject(objlist)[source]

Make a new CQ object.

Parameters:
  • objlist (a list of CAD primitives ( wire,face,edge,solid,vertex,etc )) – The stack of objects to use
  • newContextSolid – an optional new solid to become the new context solid

The parent of the new object will be set to the current object, to preserve the chain correctly.

Custom plugins and subclasses should use this method to create new CQ objects correctly.

rotateAboutCenter(axisEndPoint, angleDegrees)[source]

Rotates all items on the stack by the specified angle, about the specified axis

The center of rotation is a vector starting at the center of the object on the stack, and ended at the specified point.

Parameters:
  • axisEndPoint (a three-tuple in global coordinates) – the second point of axis of rotation
  • angleDegrees (float) – the rotation angle, in degrees
Returns:

a CQ object, with all items rotated.

WARNING: This version returns the same cq object instead of a new one– the old object is not accessible.

Future Enhancements:
  • A version of this method that returns a transformed copy, rather than modifying the originals
  • This method doesnt expose a very good interface, becaues the axis of rotation could be inconsistent between multiple objects. This is because the beginning of the axis is variable, while the end is fixed. This is fine when operating on one object, but is not cool for multiple.
shell(thickness)[source]

Remove the selected faces to create a shell of the specified thickness.

To shell, first create a solid, and in the same chain select the faces you wish to remove.

Parameters:thickness – a positive float, representing the thickness of the desired shell. Negative values shell inwards, positive values shell outwards.
Raises :ValueError if the current stack contains objects that are not faces of a solid further up in the chain.
Returns:a CQ object with the resulting shelled solid selected.

This example will create a hollowed out unit cube, where the top most face is open, and all other walls are 0.2 units thick:

Workplane().box(1,1,1).faces("+Z").shell(0.2)

Shelling is one of the cases where you may need to use the add method to select several faces. For example, this example creates a 3-walled corner, by removing three faces of a cube:

s = Workplane().box(1,1,1)
s1 = s.faces("+Z")
s1.add(s.faces("+Y")).add(s.faces("+X"))
self.saveModel(s1.shell(0.2))

This fairly yucky syntax for selecting multiple faces is planned for improvement

Note: When sharp edges are shelled inwards, they remain sharp corners, but outward shells are automatically filleted, because an outward offset from a corner generates a radius

Future Enhancements:
Better selectors to make it easier to select multiple faces
shells(selector=None)[source]

Select the shells of objects on the stack, optionally filtering the selection. If there are multiple objects on the stack, the shells of all objects are collected and a list of all the distinct shells is returned.

Parameters:selector (None, a Selector object, or a string selector expression.) – A selector
Returns:a CQ object whos stack contains all of the distinct solids of all objects on the current stack, filtered by the provided selector.

If there are no shells for any objects on the current stack, an empty CQ object is returned

Most solids will have a single shell, which represents the outer surface. A shell will typically be composed of multiple faces.

See more about selectors HERE

size()[source]

Return the number of objects currently on the stack

solids(selector=None)[source]

Select the solids of objects on the stack, optionally filtering the selection. If there are multiple objects on the stack, the solids of all objects are collected and a list of all the distinct solids is returned.

Parameters:selector (None, a Selector object, or a string selector expression.) – A selector
Returns:a CQ object whos stack contains all of the distinct solids of all objects on the current stack, filtered by the provided selector.

If there are no solids for any objects on the current stack, an empty CQ object is returned

The typical use is to select the a single object on the stack. For example:

CQ(aCube).solids().size()

returns 1, because a cube consists of one solid.

It is possible for single CQ object ( or even a single CAD primitive ) to contain multiple solids.

See more about selectors HERE

split(keepTop=False, keepBottom=False)[source]

Splits a solid on the stack into two parts, optionally keeping the separate parts.

Parameters:
  • keepTop (boolean) – True to keep the top, False or None to discard it
  • keepBottom (boolean) – True to keep the bottom, False or None to discard it
Raises :

ValueError if keepTop and keepBottom are both false.

Raises :

ValueError if there is not a solid in the current stack or the parent chain

Returns:

CQ object with the desired objects on the stack.

The most common operation splits a solid and keeps one half. This sample creates split bushing:

#drill a hole in the side
c = Workplane().box(1,1,1).faces(">Z").workplane().circle(0.25).cutThruAll()F
#now cut it in half sideways
c.faces(">Y").workplane(-0.5).split(keepTop=True)
toSvg(opts=None)[source]

Returns svg text that represents the first item on the stack.

for testing purposes.

Parameters:options (dictionary, width and height) – svg formatting options
Returns:a string that contains SVG that represents this item.
translate(vec)[source]

Returns a copy of all of the items on the stack by the specified distance

Parameters:tupleDistance (a 3-tuple of float) – distance to move, in global coordinates
Returns:a CQ object

WARNING: the underlying objects are modified, not copied.

Future Enhancements:
A version of this method that returns a transformed copy instead of modifying the originals.
val()[source]

Return the first value on the stack

Returns:the first value on the stack.
Return type:A FreeCAD object or a SolidReference
vals()[source]

get the values in the current list

Return type:list of FreeCAD objects
Returns:the values of the objects on the stack.

Contrast with all(), which returns CQ objects for all of the items on the stack

vertices(selector=None)[source]

Select the vertices of objects on the stack, optionally filtering the selection. If there are multiple objects on the stack, the vertices of all objects are collected and a list of all the distinct vertices is returned.

Parameters:selector (None, a Selector object, or a string selector expression.) –
Returns:a CQ object whos stack contains the distinct vertices of all objects on the current stack, after being filtered by the selector, if provided

If there are no vertices for any objects on the current stack, an empty CQ object is returned

The typical use is to select the vertices of a single object on the stack. For example:

Workplane().box(1,1,1).faces("+Z").vertices().size()

returns 4, because the topmost face of cube will contain four vertices. While this:

Workplane().box(1,1,1).faces().vertices().size()

returns 8, because a cube has a total of 8 vertices

Note Circles are peculiar, they have a single vertex at the center!

StringSyntaxSelector

wires(selector=None)[source]

Select the wires of objects on the stack, optionally filtering the selection. If there are multiple objects on the stack, the wires of all objects are collected and a list of all the distinct wires is returned.

Parameters:selector (None, a Selector object, or a string selector expression.) – A selector
Returns:a CQ object whos stack contains all of the distinct wires of all objects on the current stack, filtered by the provided selector.

If there are no wires for any objects on the current stack, an empty CQ object is returned

The typical use is to select the wires of a single object on the stack. For example:

CQ(aCube).faces("+Z").wires().size()

returns 1, because a face typically only has one outer wire

See more about selectors HERE

workplane(offset=0.0, invert=False)[source]

Creates a new 2-D workplane, located relative to the first face on the stack.

Parameters:
  • offset (float or None=0.0) – offset for the work plane in the Z direction. Default
  • invert (boolean or None=False) – invert the Z direction from that of the face.
Return type:

Workplane object ( which is a subclass of CQ )

The first element on the stack must be a face, or a vertex. If a vertex, then the parent item on the chain immediately before the vertex must be a face.

The result will be a 2-d working plane with a new coordinate system set up as follows:

  • The origin will be located in the center of the face, if a face was selected. If a vertex was selected, the origin will be at the vertex, and located on the face.
  • The Z direction will be normal to the plane of the face,computed at the center point.
  • The X direction will be parallel to the x-y plane. If the workplane is parallel to the global x-y plane, the x direction of the workplane will co-incide with the global x direction.

Most commonly, the selected face will be planar, and the workplane lies in the same plane of the face ( IE, offset=0). Occasionally, it is useful to define a face offset from an existing surface, and even more rarely to define a workplane based on a face that is not planar.

To create a workplane without first having a face, use the Workplane() method.

Future Enhancements:
  • Allow creating workplane from planar wires
  • Allow creating workplane based on an arbitrary point on a face, not just the center. For now you can work around by creating a workplane and then offsetting the center afterwards.
class cadfile.cadutils.cadquery.Plane(origin, xDir, normal)

A 2d coordinate system in space, with the x-y axes on the a plane, and a particular point as the origin.

A plane allows the use of 2-d coordinates, which are later converted to global, 3d coordinates when the operations are complete.

Frequently, it is not necessary to create work planes, as they can be created automatically from faces.

isWireInside(baseWire, testWire)

Determine if testWire is inside baseWire, after both wires are projected into the current plane

Parameters:
  • baseWire (a FreeCAD wire) – a reference wire
  • testWire (a FreeCAD wire) – another wire
Returns:

True if testWire is inside baseWire, otherwise False

If either wire does not lie in the current plane, it is projected into the plane first.

WARNING: This method is not 100% reliable. It uses bounding box tests, but needs more work to check for cases when curves are complex.

Future Enhancements:
  • Discretizing points along each curve to provide a more reliable test
classmethod named(stdName, origin=(0, 0, 0))

Create a predefined Plane based on the conventional names.

Parameters:
  • stdName (string) – one of (XY|YZ|XZ|front|back|left|right|top|bottom
  • origin (3-tuple of the origin of the new plane, in global coorindates.) – the desired origin, specified in global coordinates

Available named planes are as follows. Direction references refer to the global directions

Name xDir yDir zDir
XY +x +y +z
YZ +y +z +x
XZ +x +z -y
front +x +y +z
back -x +y -z
left +z +y -x
right -z +y +x
top +x -z +y
bottom +x +z -y
rotated(rotate=Vector (0, 0, 0))

returns a copy of this plane, rotated about the specified axes, as measured from horizontal

Since the z axis is always normal the plane, rotating around Z will always produce a plane that is parallel to this one

the origin of the workplane is unaffected by the rotation.

rotations are done in order x,y,z. if you need a different order, manually chain together multiple .rotate() commands

Parameters:roate – Vector [xDegrees,yDegrees,zDegrees]
Returns:a copy of this plane rotated as requested
setOrigin2d(x, y)

Set a new origin based of the plane. The plane’s orientation and xDrection are unaffected.

Parameters:
  • x (float) – offset in the x direction
  • y (float) – offset in the y direction
Returns:

void

the new coordinates are specified in terms of the current 2-d system. As an example::
p = Plane.XY() p.setOrigin2d(2,2) p.setOrigin2d(2,2)

results in a plane with its origin at (x,y)=(4,4) in global coordinates. The both operations were relative to local coordinates of the plane.

setOrigin3d(originVector)

Move the origin of the plane, leaving its orientation and xDirection unchanged. :param originVector: the new center of the plane, global coordinates :type originVector: a FreeCAD Vector. :return: void

toLocalCoords(obj)

Project the provided coordinates onto this plane.

Parameters:obj – an object or vector to convert
Returns:an object of the same type as the input, but converted to local coordinates

Most of the time, the z-coordinate returned will be zero, because most operations based on a plane are all 2-d. Occasionally, though, 3-d points outside of the current plane are transformed. One such example is Workplane.box(), where 3-d corners of a box are transformed to orient the box in space correctly.

toWorldCoords(tuplePoint)

Convert a point in local coordinates to global coordinates.

Parameters:tuplePoint (a 2 or three tuple of float. the third value is taken to be zero if not supplied) – point in local coordinates to convert
Returns:a 3-tuple in global coordinates
class cadfile.cadutils.cadquery.Workplane(inPlane, origin=(0, 0, 0), obj=None)[source]

Defines a coordinate system in space, in which 2-d coordinates can be used.

Parameters:
  • plane (a Plane object, or a string in (XY|YZ|XZ|front|back|top|bottom|left|right)) – the plane in which the workplane will be done
  • origin (a 3-tuple in global coordinates, or None to default to the origin) – the desired origin of the new workplane
  • obj (a CAD primitive, or None to use the centerpoint of the plane as the initial stack value.) – an object to use initially for the stack
Raises :

ValueError if the provided plane is not a plane, a valid named workplane

Returns:

A Workplane object, with coordinate system matching the supplied plane.

The most common use is:

s = Workplane("XY")

After creation, the stack contains a single point, the origin of the underlying plane, and the current point is on the origin.

Note

You can also create workplanes on the surface of existing faces using CQ.workplane()

add(obj)

adds an object or a list of objects to the stack

Parameters:obj (a CQ object, CAD primitive, or list of CAD primitives) – an object to add
Returns:a CQ object with the requested operation performed

If an CQ object, the values of that object’s stack are added. If a list of cad primitives, they are all added. If a single CAD primitive it is added

Used in rare cases when you need to combine the results of several CQ results into a single CQ object. Shelling is one common example

all()

Return a list of all CQ objects on the stack.

useful when you need to operate on the elements individually.

Contrast with vals, which returns the underlying objects for all of the items on the stack

box(length, width, height, centered=(True, True, True), combine=True)[source]

Return a 3d box with specified dimensions for each object on the stack.

Parameters:
  • length (float > 0) – box size in X direction
  • width (float > 0) – box size in Y direction
  • height (float > 0) – box size in Z direction
  • centered – should the box be centered, or should reference point be at the lower bound of the range?
  • combine (true to combine shapes, false otherwise.) – should the results be combined with other solids on the stack ( and each other)?

Centered is a tuple that describes whether the box should be centered on the x,y, and z axes. If true, the box is centered on the respective axis relative to the workplane origin, if false, the workplane center will represent the lower bound of the resulting box

one box is created for each item on the current stack. If no items are on the stack, one box using the current workplane center is created.

If combine is true, the result will be a single object on the stack:
if a solid was found in the chain, the result is that solid with all boxes produced fused onto it otherwise, the result is the combination of all the produced boxes

if combine is false, the result will be a list of the boxes produced

Most often boxes form the basis for a part:

#make a single box with lower left corner at origin
s = Workplane().box(1,2,3,centered=(False,False,False)

But sometimes it is useful to create an array of them:

#create 4 small square bumps on a larger base plate: s = Workplane().box(4,4,0.5).faces(“>Z”).workplane() .rect(3,3,forConstruction=True).vertices().box(0.25,0.25,0.25,combine=True)
cboreHole(diameter, cboreDiameter, cboreDepth, depth=None)[source]

Makes a counterbored hole for each item on the stack.

Parameters:
  • diameter – the diameter of the hole
  • cboreDiameter (float > 0 and > diameter) – the diameter of the cbore
  • cboreDepth (float > 0) – depth of the counterbore
  • depth (float > 0 or None to drill thru the entire part.) – the depth of the hole

The surface of the hole is at the current workplane plane.

One hole is created for each item on the stack. A very common use case is to use a construction rectangle to define the centers of a set of holes, like so:

s = Workplane(Plane.XY()).box(2,4,0.5).faces(">Z").workplane().rect(1.5,3.5,forConstruction=True)                        .vertices().cboreHole(0.125, 0.25,0.125,depth=None)

This sample creates a plate with a set of holes at the corners.

Plugin Note: this is one example of the power of plugins. Counterbored holes are quite time consuming to create, but are quite easily defined by users.

see cskHole() to make countersinks instead of counterbores

center(x, y)[source]

Shift local coordinates to the specified location.

The location is specified in terms of local coordinates.

Parameters:
  • x (float) – the new x location
  • y (float) – the new y location
Returns:

the workplane object, with the center adjusted.

The current point is set to the new center. This method is useful to adjust the center point after it has been created automatically on a face, but not where you’d like it to be.

In this example, we adjust the workplane center to be at the corner of a cube, instead of the center of a face, which is the default:

#this workplane is centered at x=0.5,y=0.5, the center of the upper face
s = Workplane().box(1,1,1).faces(">Z").workplane()

s.center(-0.5,-0.5) # move the center to the corner
t = s.circle(0.25).extrude(0.2)
assert ( t.faces().size() == 9 ) # a cube with a cylindrical nub at the top right corner

The result is a cube with a round boss on the corner

circle(radius, forConstruction=False)[source]

Make a circle for each item on the stack.

Parameters:
  • radius (float > 0) – radius of the circle
  • forConstruction (true if the wires are for reference, false if they are creating part geometry) – should the new wires be reference geometry only?
Returns:

a new CQ object with the created wires on the stack

A common use case is to use a for-construction rectangle to define the centers of a hole pattern:

s = Workplane().rect(4.0,4.0,forConstruction=True).vertices().circle(0.25)

Creates 4 circles at the corners of a square centered on the origin. Another common case is to use successive circle() calls to create concentric circles. This works because the center of a circle is its reference point:

s = Workplane().circle(2.0).circle(1.0)

Creates two concentric circles, which when extruded will form a ring.

Future Enhancements:
better way to handle forConstruction project points not in the workplane plane onto the workplane plane
close()[source]

End 2-d construction, and attempt to build a closed wire.

Returns:a CQ object with a completed wire on the stack, if possible.

After 2-d drafting with lineTo,threePointArc, and polyline, it is necessary to convert the edges produced by these into one or more wires.

When a set of edges is closed, cadQuery assumes it is safe to build the group of edges into a wire. This example builds a simple triangular prism:

s = Workplane().lineTo(1,0).lineTo(1,1).close().extrude(0.2)
combine()

Attempts to combine all of the items on the items on the stack into a single item. WARNING: all of the items must be of the same type!

Raises :ValueError if there are no items on the stack, or if they cannot be combined
Returns:a CQ object with the resulting object selected
combineSolids(otherCQToCombine=None)

!!!DEPRECATED!!! use union() Combines all solids on the current stack, and any context object, together into a single object.

After the operation, the returned solid is also the context solid.

Parameters:otherCQToCombine – another cadquery to combine.
Returns:a cQ object with the resulting combined solid on the stack.

Most of the time, both objects will contain a single solid, which is combined and returned on the stack of the new object.

compounds(selector=None)

Select compounds on the stack, optionally filtering the selection. If there are multiple objects on the stack, they are collected and a list of all the distinct compounds is returned.

Parameters:selector (None, a Selector object, or a string selector expression.) – A selector
Returns:a CQ object whos stack contains all of the distinct solids of all objects on the current stack, filtered by the provided selector.

A compound contains multiple CAD primitives that resulted from a single operation, such as a union, cut, split, or fillet. Compounds can contain multiple edges, wires, or solids.

See more about selectors HERE

consolidateWires()[source]

Attempt to consolidate wires on the stack into a single. If possible, a new object with the results are returned. if not possible, the wires remain separated

FreeCAD has a bug in Part.Wire([]) which does not create wires/edges properly somtimes Additionally, it has a bug where a profile compose of two wires ( rathre than one ) also does not work properly

together these are a real problem.

cskHole(diameter, cskDiameter, cskAngle, depth=None)[source]

Makes a countersunk hole for each item on the stack.

Parameters:
  • diameter – the diameter of the hole
  • cskDiameter (float > 0 and > diameter) – the diameter of the countersink
  • cskAngle (float > 0) – angle of the countersink, in degrees ( 82 is common )
  • depth (float > 0 or None to drill thru the entire part.) – the depth of the hole

The surface of the hole is at the current workplane.

One hole is created for each item on the stack. A very common use case is to use a construction rectangle to define the centers of a set of holes, like so:

s = Workplane(Plane.XY()).box(2,4,0.5).faces(">Z").workplane().rect(1.5,3.5,forConstruction=True)                        .vertices().cskHole(0.125, 0.25,82,depth=None)

This sample creates a plate with a set of holes at the corners.

Plugin Note: this is one example of the power of plugins. CounterSunk holes are quite time consuming to create, but are quite easily defined by users.

see cboreHole() to make counterbores instead of countersinks

cut(toCut, combine=True)[source]

Cuts the provided solid from the current solid, IE, perform a solid subtraction

if combine=True, the result and the original are updated to point to the new object if combine=False, the result will be on the stack, but the original is unmodified

Parameters:toCut (a solid object, or a CQ object having a solid,) – object to cut
Raises :ValueError if there is no solid to subtract from in the chain
Returns:a CQ object with the resulting object selected
cutBlind(distanceToCut)[source]

Use all un-extruded wires in the parent chain to create a prismatic cut from existing solid.

Similar to extrude, except that a solid in the parent chain is required to remove material from. cutBlind always removes material from a part.

Parameters:distanceToCut (float, >0 means in the positive direction of the workplane normal, <0 means in the negative direction) – distance to extrude before cutting
Raises :ValueError if there is no solid to subtract from in the chain
Returns:a CQ object with the resulting object selected

see cutThruAll() to cut material from the entire part

Future Enhancements:
Cut Up to Surface
cutEach(fcn, useLocalCoords=False)[source]

Evaluates the provided function at each point on the stack ( ie, eachpoint ) and then cuts the result from the context solid. :param function: a function suitable for use in the eachpoint method: ie, that accepts a vector :param useLocalCoords: same as for eachpoint() :return: a CQ object that contains the resulting solid :raises: an error if there is not a context solid to cut from

cutThruAll(positive=False)[source]

Use all un-extruded wires in the parent chain to create a prismatic cut from existing solid.

Similar to extrude, except that a solid in the parent chain is required to remove material from. cutThruAll always removes material from a part.

Parameters:positive (boolean) – True to cut in the positive direction, false to cut in the negative direction
Raises :ValueError if there is no solid to subtract from in the chain
Returns:a CQ object with the resulting object selected

see cutBlind() to cut material to a limited depth

each(callBackFunction, useLocalCoordinates=False)[source]

runs the provided function on each value in the stack, and collects the return values into a new CQ object.

Special note: a newly created workplane always has its center point as its only stack item

Parameters:
  • callBackFunction – the function to call for each item on the current stack.
  • useLocalCoordinates (boolean) – should values be converted from local coordinates first?

The callback function must accept one argument, which is the item on the stack, and return one object, which is collected. If the function returns None, nothing is added to the stack. The object passed into the callBackFunction is potentially transformed to local coordinates, if useLocalCoordinates is true

useLocalCoordinates is very useful for plugin developers.

If false, the callback function is assumed to be working in global coordinates. Objects created are added as-is, and objects passed into the function are sent in using global coordinates

If true, the calling function is assumed to be working in local coordinates. Objects are transformed to local coordinates before they are passed into the callback method, and result objects are transformed to global coorindates after they are returned.

This allows plugin developers to create objects in local coordinates, without worrying about the fact that the working plane is different than the global coordinate system.

TODO: wrapper object for Wire will clean up forConstruction flag everywhere

eachpoint(callbackFunction, useLocalCoordinates=False)[source]

Same as each(), except each item on the stack is converted into a point before it is passed into the callback function.

Returns:CadQuery object which contains a list of vectors (points ) on its stack.
Parameters:useLocalCoordinates (boolean) – should points be in local or global coordinates

The resulting object has a point on the stack for each object on the original stack. Vertices and points remain a point. Faces, Wires, Solids, Edges, and Shells are converted to a point by using their center of mass.

If the stack has zero length, a single point is returned, which is the center of the current workplane/coordinate system

edges(selector=None)

Select the edges of objects on the stack, optionally filtering the selection. If there are multiple objects on the stack, the edges of all objects are collected and a list of all the distinct edges is returned.

Parameters:selector (None, a Selector object, or a string selector expression.) – A selector
Returns:a CQ object whos stack contains all of the distinct edges of all objects on the current stack, filtered by the provided selector.

If there are no edges for any objects on the current stack, an empty CQ object is returned

The typical use is to select the edges of a single object on the stack. For example:

CQ(aCube).faces("+Z").edges().size()

returns 4, because a cube has one face with a normal in the +Z direction. Similarly:

CQ(aCube).edges().size()

returns 12, because a cube has a total of 12 edges, And:

CQ(aCube).edges("|Z").size()

returns 4, because a cube has 4 edges parallel to the z direction

See more about selectors HERE

end()

Return the parent of this CQ element :rtype: a CQ object :raises: ValueError if there are no more parents in the chain.

For example:

CQ(obj).faces("+Z").vertices().end()

will return the same as:

CQ(obj).faces("+Z")
exportSvg(fileName)

Exports the first item on the stack as an SVG file

For testing purposes mainly.

Parameters:fileName (String, absolute path to the file) – the filename to export
extrude(distance, combine=True)[source]

Use all un-extruded wires in the parent chain to create a prismatic solid.

Parameters:
  • distance (float, negative means opposite the normal direction) – the distance to extrude, normal to the workplane plane
  • combine (boolean) – True to combine the resulting solid with parent solids if found.
Returns:

a CQ object with the resulting solid selected.

extrude always adds material to a part.

The returned object is always a CQ object, and depends on wither combine is True, and whether a context solid is already defined:

  • if combine is False, the new value is pushed onto the stack.
  • if combine is true, the value is combined with the context solid if it exists, and the resulting solid becomes the new context solid.
FutureEnhancement:
Support for non-prismatic extrusion ( IE, sweeping along a profile, not just perpendicular to the plane extrude to surface. this is quite tricky since the surface selected may not be planar
faces(selector=None)

Select the faces of objects on the stack, optionally filtering the selection. If there are multiple objects on the stack, the faces of all objects are collected and a list of all the distinct faces is returned.

Parameters:selector (None, a Selector object, or a string selector expression.) – A selector
Returns:a CQ object whos stack contains all of the distinct faces of all objects on the current stack, filtered by the provided selector.

If there are no vertices for any objects on the current stack, an empty CQ object is returned

The typical use is to select the faces of a single object on the stack. For example:

CQ(aCube).faces("+Z").size()

returns 1, because a cube has one face with a normal in the +Z direction. Similarly:

CQ(aCube).faces().size()

returns 6, because a cube has a total of 6 faces, And:

CQ(aCube).faces("|Z").size()

returns 2, because a cube has 2 faces having normals parallel to the z direction

See more about selectors HERE

fillet(radius)

Fillets a solid on the selected edges.

The edges on the stack are filleted. The solid to which the edges belong must be in the parent chain of the selected edges.

Parameters:radius (positive float) – the radius of the fillet, must be > zero
Raises :ValueError if at least one edge is not selected
Raises :ValueError if the solid containing the edge is not in the chain
Returns:cq object with the resulting solid selected.

This example will create a unit cube, with the top edges filleted:

s = Workplane().box(1,1,1).faces("+Z").edges().fillet(0.1)
findSolid(searchStack=True, searchParents=True)

Finds the first solid object in the chain, searching from the current node backwards through parents until one is found.

Parameters:
  • searchStack – should objects on the stack be searched first.
  • searchParents – should parents be searched?
Raises :

ValueError if no solid is found in the current object or its parents, and errorOnEmpty is True

This function is very important for chains that are modifying a single parent object, most often a solid.

Most of the time, a chain defines or selects a solid, and then modifies it using workplanes or other operations.

Plugin Developers should make use of this method to find the solid that should be modified, if the plugin implements a unary operation, or if the operation will automatically merge its results with an object already on the stack.

first()

Return the first item on the stack :returns: the first item on the stack. :rtype: a CQ object

hLine(distance, forConstruction=False)[source]

Make a horizontal line from the current point the provided distance

Parameters:distance (float) –
  1. distance from current point
Returns:the Workplane object with the current point at the end of the new line
hLineTo(xCoord, forConstruction=False)[source]

Make a horizontal line from the curren tpoint to the provided x coordinate.

Useful if it is more convienient to specify the end location rather than distance, as in hLine()

Parameters:xCoord (float) – x coordinate for the end of the line
Returns:the Workplane object with the current point at the end of the new line
hole(diameter, depth=None)[source]

Makes a hole for each item on the stack.

Parameters:
  • diameter – the diameter of the hole
  • depth (float > 0 or None to drill thru the entire part.) – the depth of the hole

The surface of the hole is at the current workplane.

One hole is created for each item on the stack. A very common use case is to use a construction rectangle to define the centers of a set of holes, like so:

s = Workplane(Plane.XY()).box(2,4,0.5).faces(">Z").workplane().rect(1.5,3.5,forConstruction=True)                        .vertices().hole(0.125, 0.25,82,depth=None)

This sample creates a plate with a set of holes at the corners.

Plugin Note: this is one example of the power of plugins. CounterSunk holes are quite time consuming to create, but are quite easily defined by users.

see cboreHole() and cskHole() to make counterbores or countersinks

item(i)

Return the ith item on the stack. :rtype: a CQ object

largestDimension()[source]

Finds the largest dimension in the stack. Used internally to create thru features, this is how you can compute how long or wide a feature must be to make sure to cut through all of the material :return:

last()

Return the last item on the stack. :rtype: a CQ object

line(xDist, yDist, forConstruction=False)[source]

Make a line from the current point to the provided point, using dimensions relative to the current point

Parameters:
  • xDist (float) – x distance from current point
  • yDist (float) – y distance from current point
Returns:

the workplane object with the current point at the end of the new line

see lineTo() if you want to use absolute coordinates to make a line instead.

lineTo(x, y, forConstruction=False)[source]

Make a line from the current point to the provided point

Parameters:
  • x (float) – the x point, in workplane plane coordinates
  • y (float) – the y point, in workplane plane coordinates
Returns:

the Workplane object with the current point at the end of the new line

see line() if you want to use relative dimensions to make a line instead.

loft(filled=True, combine=True)[source]

Make a lofted solid, through the set of wires. :return:

mirrorX()[source]

Mirror entities around the x axis of the workplane plane.

Returns:a new object with any free edges consolidated into as few wires as possible.

All free edges are collected into a wire, and then the wire is mirrored, and finally joined into a new wire

Typically used to make creating wires with symmetry easier.

Future Enhancements:
mirrorX().mirrorY() should work but doesnt, due to some FreeCAD weirdness
mirrorY()[source]

Mirror entities around the y axis of the workplane plane.

Returns:a new object with any free edges consolidated into as few wires as possible.

All free edges are collected into a wire, and then the wire is mirrored, and finally joined into a new wire

Typically used to make creating wires with symmetry easier. This line of code:

s = Workplane().lineTo(2,2).threePointArc((3,1),(2,0)).mirrorX().extrude(0.25)

Produces a flat, heart shaped object

Future Enhancements:
mirrorX().mirrorY() should work but doesnt, due to some FreeCAD weirdness
move(xDist=0, yDist=0)[source]

Move the specified distance from the current point, without drawing.

Parameters:
  • xDist (float, or none for zero) – desired x distance, in local coordinates
  • yDist (float, or none for zero.) – desired y distance, in local coorindates

Not to be confused with center(), which moves the center of the entire workplane, this method only moves the current point ( and therefore does not affect objects already drawn ).

See moveTo() to do the same thing but using absolute coordinates

moveTo(x=0, y=0)[source]

Move to the specified point, without drawing.

Parameters:
  • x (float, or none for zero) – desired x location, in local coordinates
  • y (float, or none for zero.) – desired y location, in local coorindates

Not to be confused with center(), which moves the center of the entire workplane, this method only moves the current point ( and therefore does not affect objects already drawn ).

See move() to do the same thing but using relative dimensions

newObject(objlist)[source]

Create a new workplane object from this one.

Overrides CQ.newObject, and should be used by extensions, plugins, and subclasses to create new objects.

Parameters:objlist (a list of CAD primitives) – new objects to put on the stack
Returns:a new Workplane object with the current workplane as a parent.
polygon(nSides, diameter)[source]

Creates a polygon incribed in a circle of the specified diamter for each point on the stack

The first vertex is always oriented in the x direction.

Parameters:
  • nSides – number of sides, must be > 3
  • diameter – the size of the circle the polygon is incribed into
Returns:

a polygon wire

polyline(listOfXYTuple, forConstruction=False)[source]

Create a polyline from a list of points

Parameters:
  • listOfXYTuple (list of 2-tuples) – a list of points in Workplane coordinates
  • forConstruction (true if the wire is for reference, false if they are creating part geometry) – should the new wire be reference geometry only?
Returns:

a new CQ object with the new wire on the stack

NOTE most commonly, the resulting wire should be closed.

Future Enhacement:
This should probably yield a list of edges, not a wire, so that it is possible to combine a polyline with other edges and arcs
pushPoints(pntList)[source]

Pushes a list of points onto the stack as vertices. The points are in the 2-d coordinate space of the workplane face

Parameters:pntList (list of 2-tuples, in local coordinates) – a list of points to push onto the stack
Returns:a new workplane with the desired points on the stack.

A common use is to provide a list of points for a subsequent operation, such as creating circles or holes. This example creates a cube, and then drills three holes through it, based on three points:

s = Workplane().box(1,1,1).faces(">Z").workplane().pushPoints([(-0.3,0.3),(0.3,0.3),(0,0)])
body = s.circle(0.05).cutThruAll()

Here the circle function operates on all three points, and is then extruded to create three holes. See circle() for how it works.

rarray(xSpacing, ySpacing, xCount, yCount, center=True)

Creates an array of points and pushes them onto the stack. If you want to position the array at another point, create another workplane that is shifted to the position you would like to use as a reference

Parameters:
  • xSpacing – spacing between points in the x direction ( must be > 0)
  • ySpacing – spacing between points in the y direction ( must be > 0)
  • xCount – number of points ( > 0 )
  • yCount – number of poitns ( > 0 )
  • center – if true, the array will be centered at the center of the workplane. if false, the lower left corner will be at the center of the work plane
rect(xLen, yLen, centered=True, forConstruction=False)[source]

Make a rectangle for each item on the stack.

Parameters:
  • xLen (float > 0) – length in xDirection ( in workplane coordinates )
  • yLen (float > 0) – length in yDirection ( in workplane coordinates )
  • centered (boolean) – true if the rect is centered on the reference point, false if the lower-left is on the reference point
  • forConstruction (true if the wires are for reference, false if they are creating part geometry) – should the new wires be reference geometry only?
Returns:

a new CQ object with the created wires on the stack

A common use case is to use a for-construction rectangle to define the centers of a hole pattern:

s = Workplane().rect(4.0,4.0,forConstruction=True).vertices().circle(0.25)

Creates 4 circles at the corners of a square centered on the origin.

Future Enhancements:
better way to handle forConstruction project points not in the workplane plane onto the workplane plane
rotateAboutCenter(axisEndPoint, angleDegrees)

Rotates all items on the stack by the specified angle, about the specified axis

The center of rotation is a vector starting at the center of the object on the stack, and ended at the specified point.

Parameters:
  • axisEndPoint (a three-tuple in global coordinates) – the second point of axis of rotation
  • angleDegrees (float) – the rotation angle, in degrees
Returns:

a CQ object, with all items rotated.

WARNING: This version returns the same cq object instead of a new one– the old object is not accessible.

Future Enhancements:
  • A version of this method that returns a transformed copy, rather than modifying the originals
  • This method doesnt expose a very good interface, becaues the axis of rotation could be inconsistent between multiple objects. This is because the beginning of the axis is variable, while the end is fixed. This is fine when operating on one object, but is not cool for multiple.
rotateAndCopy(matrix)[source]

Makes a copy of all edges on the stack, rotates them according to the provided matrix, and then attempts to consolidate them into a single wire.

Parameters:matrix (a FreeCAD Base.Matrix object) – a 4xr transformation matrix, in global coordinates
Returns:a cadquery object with consolidated wires, and any originals on the stack.

The most common use case is to create a set of open edges, and then mirror them around either the X or Y axis to complete a closed shape.

see mirrorX() and mirrorY() to mirror about the global X and Y axes see mirrorX() and for an example

Future Enhancements:
faster implementation: this one transforms 3 times to accomplish the result
shell(thickness)

Remove the selected faces to create a shell of the specified thickness.

To shell, first create a solid, and in the same chain select the faces you wish to remove.

Parameters:thickness – a positive float, representing the thickness of the desired shell. Negative values shell inwards, positive values shell outwards.
Raises :ValueError if the current stack contains objects that are not faces of a solid further up in the chain.
Returns:a CQ object with the resulting shelled solid selected.

This example will create a hollowed out unit cube, where the top most face is open, and all other walls are 0.2 units thick:

Workplane().box(1,1,1).faces("+Z").shell(0.2)

Shelling is one of the cases where you may need to use the add method to select several faces. For example, this example creates a 3-walled corner, by removing three faces of a cube:

s = Workplane().box(1,1,1)
s1 = s.faces("+Z")
s1.add(s.faces("+Y")).add(s.faces("+X"))
self.saveModel(s1.shell(0.2))

This fairly yucky syntax for selecting multiple faces is planned for improvement

Note: When sharp edges are shelled inwards, they remain sharp corners, but outward shells are automatically filleted, because an outward offset from a corner generates a radius

Future Enhancements:
Better selectors to make it easier to select multiple faces
shells(selector=None)

Select the shells of objects on the stack, optionally filtering the selection. If there are multiple objects on the stack, the shells of all objects are collected and a list of all the distinct shells is returned.

Parameters:selector (None, a Selector object, or a string selector expression.) – A selector
Returns:a CQ object whos stack contains all of the distinct solids of all objects on the current stack, filtered by the provided selector.

If there are no shells for any objects on the current stack, an empty CQ object is returned

Most solids will have a single shell, which represents the outer surface. A shell will typically be composed of multiple faces.

See more about selectors HERE

size()

Return the number of objects currently on the stack

solids(selector=None)

Select the solids of objects on the stack, optionally filtering the selection. If there are multiple objects on the stack, the solids of all objects are collected and a list of all the distinct solids is returned.

Parameters:selector (None, a Selector object, or a string selector expression.) – A selector
Returns:a CQ object whos stack contains all of the distinct solids of all objects on the current stack, filtered by the provided selector.

If there are no solids for any objects on the current stack, an empty CQ object is returned

The typical use is to select the a single object on the stack. For example:

CQ(aCube).solids().size()

returns 1, because a cube consists of one solid.

It is possible for single CQ object ( or even a single CAD primitive ) to contain multiple solids.

See more about selectors HERE

spline(listOfXYTuple, forConstruction=False)[source]

Create a spline interpolated through the provided points.

Parameters:listOfXYTuple (list of 2-tuple) – points to interpolate through
Returns:a Workplane object with the current point at the end of the spline

The spline will begin at the current point, and end with the last point in the XY typle list

This example creates a block with a spline for one side:

s = Workplane(Plane.XY())
sPnts = [
    (2.75,1.5),
    (2.5,1.75),
    (2.0,1.5),
    (1.5,1.0),
    (1.0,1.25),
    (0.5,1.0),
    (0,1.0)
]
r = s.lineTo(3.0,0).lineTo(3.0,1.0).spline(sPnts).close()
r = r.extrude(0.5)

WARNING It is fairly easy to create a list of points that cannot be correctly interpreted as a spline.

Future Enhancements:
  • provide access to control points
split(keepTop=False, keepBottom=False)

Splits a solid on the stack into two parts, optionally keeping the separate parts.

Parameters:
  • keepTop (boolean) – True to keep the top, False or None to discard it
  • keepBottom (boolean) – True to keep the bottom, False or None to discard it
Raises :

ValueError if keepTop and keepBottom are both false.

Raises :

ValueError if there is not a solid in the current stack or the parent chain

Returns:

CQ object with the desired objects on the stack.

The most common operation splits a solid and keeps one half. This sample creates split bushing:

#drill a hole in the side
c = Workplane().box(1,1,1).faces(">Z").workplane().circle(0.25).cutThruAll()F
#now cut it in half sideways
c.faces(">Y").workplane(-0.5).split(keepTop=True)
threePointArc(point1, point2, forConstruction=False)[source]

Draw an arc from the current point, through point1, and ending at point2

Parameters:
  • point1 (2-tuple, in workplane coordinates) – point to draw through
  • point2 (2-tuple, in workplane coordinates) – end point for the arc
Returns:

a workplane with the current point at the end of the arc

Future Enhancments:
provide a version that allows an arc using relative measures provide a centerpoint arc provide tangent arcs
toSvg(opts=None)

Returns svg text that represents the first item on the stack.

for testing purposes.

Parameters:options (dictionary, width and height) – svg formatting options
Returns:a string that contains SVG that represents this item.
transformed(rotate=Vector (0, 0, 0), offset=Vector (0, 0, 0))[source]

Create a new workplane based on the current one. The origin of the new plane is located at the existing origin+offset vector, where offset is given in coordinates local to the current plane The new plane is rotated through the angles specified by the components of the rotation vector :param rotate: vector of angles to rotate, in degrees relative to work plane coordinates :param offset: vector to offset the new plane, in local work plane coordinates :return: a new work plane, transformed as requested

translate(vec)

Returns a copy of all of the items on the stack by the specified distance

Parameters:tupleDistance (a 3-tuple of float) – distance to move, in global coordinates
Returns:a CQ object

WARNING: the underlying objects are modified, not copied.

Future Enhancements:
A version of this method that returns a transformed copy instead of modifying the originals.
twistExtrude(distance, angleDegrees, combine=True)

Extrudes a wire in the direction normal to the plane, but also twists by the specified angle over the length of the extrusion

The center point of the rotation will be the center of the workplane

See extrude for more details, since this method is the same except for the the addition of the angle. in fact, if angle=0, the result is the same as a linear extrude.

NOTE This method can create complex calculations, so be careful using it with complex geometries

Parameters:
  • distance – the distance to extrude normal to the workplane
  • angle – angline ( in degrees) to rotate through the extrusion
  • combine (boolean) – True to combine the resulting solid with parent solids if found.
Returns:

a CQ object with the resulting solid selected.

union(toUnion=None, combine=True)
Unions all of the items on the stack of toUnion with the current solid.
If there is no current solid, the items in toUnion are unioned together. if combine=True, the result and the original are updated to point to the new object if combine=False, the result will be on the stack, but the original is unmodified
Parameters:toUnion (a solid object, or a CQ object having a solid,) –
Raises :ValueError if there is no solid to add to in the chain
Returns:a CQ object with the resulting object selected
vLine(distance, forConstruction=False)[source]

Make a vertical line from the current point the provided distance

Parameters:distance (float) –
  1. distance from current point
Returns:the workplane object with the current point at the end of the new line
vLineTo(yCoord, forConstruction=False)[source]

Make a vertcial line from the current point to the provided y coordinate.

Useful if it is more convienient to specify the end location rather than distance, as in vLine()

Parameters:yCoord (float) – y coordinate for the end of the line
Returns:the Workplane object with the current point at the end of the new line
val()

Return the first value on the stack

Returns:the first value on the stack.
Return type:A FreeCAD object or a SolidReference
vals()

get the values in the current list

Return type:list of FreeCAD objects
Returns:the values of the objects on the stack.

Contrast with all(), which returns CQ objects for all of the items on the stack

vertices(selector=None)

Select the vertices of objects on the stack, optionally filtering the selection. If there are multiple objects on the stack, the vertices of all objects are collected and a list of all the distinct vertices is returned.

Parameters:selector (None, a Selector object, or a string selector expression.) –
Returns:a CQ object whos stack contains the distinct vertices of all objects on the current stack, after being filtered by the selector, if provided

If there are no vertices for any objects on the current stack, an empty CQ object is returned

The typical use is to select the vertices of a single object on the stack. For example:

Workplane().box(1,1,1).faces("+Z").vertices().size()

returns 4, because the topmost face of cube will contain four vertices. While this:

Workplane().box(1,1,1).faces().vertices().size()

returns 8, because a cube has a total of 8 vertices

Note Circles are peculiar, they have a single vertex at the center!

StringSyntaxSelector

wire(forConstruction=False)[source]

Returns a CQ object with all pending edges connected into a wire.

All edges on the stack that can be combined will be combined into a single wire object, and other objects will remain on the stack unmodified

Parameters:forConstruction (boolean. true if the object is only for reference) – whether the wire should be used to make a solid, or if it is just for reference

This method is primarily of use to plugin developers making utilites for 2-d construction. This method shoudl be called when a user operation implies that 2-d construction is finished, and we are ready to begin working in 3d

SEE ‘2-d construction concepts’ for a more detailed explanation of how cadquery handles edges, wires, etc

Any non edges will still remain.

wires(selector=None)

Select the wires of objects on the stack, optionally filtering the selection. If there are multiple objects on the stack, the wires of all objects are collected and a list of all the distinct wires is returned.

Parameters:selector (None, a Selector object, or a string selector expression.) – A selector
Returns:a CQ object whos stack contains all of the distinct wires of all objects on the current stack, filtered by the provided selector.

If there are no wires for any objects on the current stack, an empty CQ object is returned

The typical use is to select the wires of a single object on the stack. For example:

CQ(aCube).faces("+Z").wires().size()

returns 1, because a face typically only has one outer wire

See more about selectors HERE

workplane(offset=0.0, invert=False)

Creates a new 2-D workplane, located relative to the first face on the stack.

Parameters:
  • offset (float or None=0.0) – offset for the work plane in the Z direction. Default
  • invert (boolean or None=False) – invert the Z direction from that of the face.
Return type:

Workplane object ( which is a subclass of CQ )

The first element on the stack must be a face, or a vertex. If a vertex, then the parent item on the chain immediately before the vertex must be a face.

The result will be a 2-d working plane with a new coordinate system set up as follows:

  • The origin will be located in the center of the face, if a face was selected. If a vertex was selected, the origin will be at the vertex, and located on the face.
  • The Z direction will be normal to the plane of the face,computed at the center point.
  • The X direction will be parallel to the x-y plane. If the workplane is parallel to the global x-y plane, the x direction of the workplane will co-incide with the global x direction.

Most commonly, the selected face will be planar, and the workplane lies in the same plane of the face ( IE, offset=0). Occasionally, it is useful to define a face offset from an existing surface, and even more rarely to define a workplane based on a face that is not planar.

To create a workplane without first having a face, use the Workplane() method.

Future Enhancements:
  • Allow creating workplane from planar wires
  • Allow creating workplane based on an arbitrary point on a face, not just the center. For now you can work around by creating a workplane and then offsetting the center afterwards.
class cadfile.cadutils.cadquery.Selector[source]

Filters a list of objects

Filters must provide a single method that filters objects.

filter(objectList)[source]

Filter the provided list :param objectList: list to filter :type objectList: list of FreeCAD primatives :return: filtered list

The default implementation returns the original list unfiltered

class cadfile.cadutils.cadquery.NearestToPointSelector(pnt)[source]

Selects object nearest the provided point.

If the object is a vertex or point, the distance is used. For other kinds of shapes, the center of mass is used to to compute which is closest.

Applicability: All Types of Shapes

Example:

CQ(aCube).vertices(NearestToPointSelector((0,1,0))

returns the vertex of the unit cube closest to the point x=0,y=1,z=0

class cadfile.cadutils.cadquery.ParallelDirSelector(vector, tolerance=0.0001)[source]

Selects objects parallel with the provided direction

Applicability:
Linear Edges Planar Faces

Use the string syntax shortcut |(X|Y|Z) if you want to select based on a cardinal direction.

Example:

CQ(aCube).faces(ParallelDirSelector((0,0,1))

selects faces with a normals in the z direction, and is equivalent to:

CQ(aCube).faces("|Z")
class cadfile.cadutils.cadquery.DirectionSelector(vector, tolerance=0.0001)[source]

Selects objects aligned with the provided direction

Applicability:
Linear Edges Planar Faces

Use the string syntax shortcut +/-(X|Y|Z) if you want to select based on a cardinal direction.

Example:

CQ(aCube).faces(DirectionSelector((0,0,1))

selects faces with a normals in the z direction, and is equivalent to:

CQ(aCube).faces("+Z")
class cadfile.cadutils.cadquery.PerpendicularDirSelector(vector, tolerance=0.0001)[source]

Selects objects perpendicular with the provided direction

Applicability:
Linear Edges Planar Faces

Use the string syntax shortcut #(X|Y|Z) if you want to select based on a cardinal direction.

Example:

CQ(aCube).faces(PerpendicularDirSelector((0,0,1))

selects faces with a normals perpendicular to the z direction, and is equivalent to:

CQ(aCube).faces("#Z")
class cadfile.cadutils.cadquery.TypeSelector(typeString)[source]

Selects objects of the prescribed topological type.

Applicability:
Faces: Plane,Cylinder,Sphere Edges: Line,Circle,Arc

You can use the shortcut selector %(PLANE|SPHERE|CONE) for faces, and %(LINE|ARC|CIRCLE) for edges.

For example this:

CQ(aCube).faces ( TypeSelector("PLANE") )

will select 6 faces, and is equivalent to:

CQ(aCube).faces( "%PLANE" )
class cadfile.cadutils.cadquery.DirectionMinMaxSelector(vector, directionMax=True)[source]

Selects objects closest or farthest in the specified direction Used for faces, points, and edges

Applicability:
All object types. for a vertex, its point is used. for all other kinds of objects, the center of mass of the object is used.

You can use the string shortcuts >(X|Y|Z) or <(X|Y|Z) if you want to select based on a cardinal direction.

For example this:

CQ(aCube).faces ( DirectionMinMaxSelector((0,0,1),True )

Means to select the face having the center of mass farthest in the positive z direction, and is the same as:

CQ(aCube).faces( “>Z” )
Future Enhancements:
provide a nicer way to select in arbitrary directions. IE, a bit more code could allow ‘>(0,0,1)’ to work.
class cadfile.cadutils.cadquery.StringSyntaxSelector(selectorString)[source]

Filter lists objects using a simple string syntax. All of the filters available in the string syntax are also available ( usually with more functionality ) through the creation of full-fledged selector objects. see Selector and its subclasses

Filtering works differently depending on the type of object list being filtered.

Parameters:selectorString – A two-part selector string, [selector][axis]
Returns:objects that match the specified selector

*Modfiers* are ('|','+','-','<','>','%')

|:parallel to ( same as ParallelDirSelector ). Can return multiple objects.
#:perpendicular to (same as PerpendicularDirSelector )
+:positive direction (same as DirectionSelector )
-:negative direction (same as DirectionSelector )
>:maximize (same as DirectionMinMaxSelector with directionMax=True)
<:minimize (same as DirectionMinMaxSelector with directionMax=False )
%:curve/surface type (same as TypeSelector)

*axisStrings* are: X,Y,Z,XY,YZ,XZ

Selectors are a complex topic: see CadQuery String Selectors for more information

filter(objectList)[source]

selects minimum, maximum, positive or negative values relative to a direction [+|-|<|>|] <X|Y|Z>

Table Of Contents

Previous topic

CadQuery String Selectors

Next topic

The Parametric Parts Build Service