1. Products
  2.   CAD
  3.   Python
  4.   CadQuery
 
  

Open Source Python Library for 3D CAD File Formats

Free Python CAD library to Create Parametric 3D CAD Models. It Create High Quality CAD Formats like STEP, AMF & 3MF and Work with Polygon.

What is CadQuery Library?

An intuitive Python library for creating parametric 3D CAD models is CadQuery, which is open source. The library is incredibly robust and can generate high-quality CAD models inside Python applications with the help of brief scripts. Additionally, the script can be customized to create a wide variety of things using just one script. CadQuery scripts are incredibly quick and can build STL, STEP, AMF, and 3MF more quickly than other libraries.

The library provides sophisticated modeling features like lofts, parametric curves, fillets, and curvilinear extrudes. End users can simply alter the parametric model created by this script-based library. It uses programs to generate 3D models that closely resemble your description of the object. The Apache Public License, version 2.0, governs CadQuery's licensing.

The CadQuery library is purposefully made to be GUI-less so that it may be utilized in scientific and engineering applications to create 3D models programmatically. Consider the Jupyter extension jupyter-cadquery or the Qt-based GUI CQ-editor if you must use a GUI. The library can also be used in conjunction with other Python libraries.

Previous Next

Getting Started with CadQuery

The easiest way to install CadQuery stable release is using pip. Please use the following command for a smooth installation.

Install CadQuery via pip

pip install cadquery 

You can download the compiled shared library from Github repository.

Work with Polygon via Python 3D Library

A polygon is a two-dimensional shape with straight sides. Polygonal modeling is an approach for modeling objects by representing or approximating their surfaces using polygon meshes. The Open source Python Library CadQuery enables software developers to create polygons for each stack point with just a couple of lines of Python code. It is very beneficial in 3d printers whose firmware does not correct for small hole sizes.

Create Workplanes on Faces via Python 3D Library

The Open source Python Library CadQuery has provided complete support for creating Workplanes on Faces inside Python applications. the use of workplanes in this way are a key feature of CadQuery. It frees users from searching the position of various features in variables, and enables the model to delete the redundant dimensions. Users can select the faces of the resultant solid by calling the Workplane.faces () method. Please remember that by default the origin of a new workplane is calculated by making a plane from the selected face and projecting the previous origin onto that plane.

How to Create Workplanes on Faces via Python API?

result = cq.Workplane("front").box(2, 3, 0.5)  # make a basic prism
result = result.faces(">Z").workplane().hole(0.5)  # find the top-most face and make a hole
 

Working with 3D LEGO Bricks via Python

The CadQuery library has provided complete support for creating 3D animation representing the Lego bricks in different size using Python commands. It is also possible to recreate bricks by joining several cubes and cylinders together. We can create a compound object to join these 3D shapes together in a single object (brick). The following example demonstrates how to generate any size regular rectangular Lego(TM) brick. It’s only tricky because of the logic regarding the underside of the brick.

How to Create 3D LEGO Bricks via Python Library?

#####
# Inputs
######
lbumps = 6       # number of bumps long
wbumps = 2       # number of bumps wide
thin = True      # True for thin, False for thick

#
# Lego Brick Constants-- these make a lego brick a lego :)
#
pitch = 8.0
clearance = 0.1
bumpDiam = 4.8
bumpHeight = 1.8
if thin:
    height = 3.2
else:
    height = 9.6

t = (pitch - (2 * clearance) - bumpDiam) / 2.0
postDiam = pitch - t  # works out to 6.5
total_length = lbumps*pitch - 2.0*clearance
total_width = wbumps*pitch - 2.0*clearance

# make the base
s = cq.Workplane("XY").box(total_length, total_width, height)

# shell inwards not outwards
s = s.faces("Z").workplane(). \
    rarray(pitch, pitch, lbumps, wbumps, True).circle(bumpDiam / 2.0) \
    .extrude(bumpHeight)

# add posts on the bottom. posts are different diameter depending on geometry
# solid studs for 1 bump, tubes for multiple, none for 1x1
tmp = s.faces(" 1 and wbumps > 1:
    tmp = tmp.rarray(pitch, pitch, lbumps - 1, wbumps - 1, center=True). \
        circle(postDiam / 2.0).circle(bumpDiam / 2.0).extrude(height - t)
elif lbumps > 1:
    tmp = tmp.rarray(pitch, pitch, lbumps - 1, 1, center=True). \
        circle(t).extrude(height - t)
elif wbumps > 1:
    tmp = tmp.rarray(pitch, pitch, 1, wbumps - 1, center=True). \
        circle(t).extrude(height - t)
else:
    tmp = s

# Render the solid
build_object(tmp)
 English