Visualization
Pure Python
Since version 2.4 CadQuery supports visualization without any external tools. Those facilities are based on the VTK library and are not tied to any external tool.
from cadquery import *
from cadquery.vis import show
w = Workplane().sphere(1).split(keepBottom=True) - Workplane().sphere(0.5)
r = w.faces('>Z').fillet(0.1)
# Show the result
show(r, alpha=0.5)
One can visualize objects of type Workplane
, Sketch
, Assembly
, Shape
,
Vector
, Location
and lists thereof.
from cadquery import *
from cadquery.occ_impl.shapes import *
from cadquery.vis import show
w = Workplane().sphere(0.5).split(keepTop=True)
sk = Sketch().rect(1.5, 1.5)
sh = torus(5, 0.5)
r = rect(2, 2)
c = circle(2)
N = 50
params = [i/N for i in range(N)]
vecs = r.positions(params)
locs = c.locations(params)
# Render the solid
show(w, sk, sh, vecs, locs)
Additionally it is possible to integrate with other libraries using VTK and display any vtkProp object.
from cadquery.vis import show
from cadquery.occ_impl.shapes import torus
from vtkmodules.vtkRenderingAnnotation import vtkAnnotatedCubeActor
a = vtkAnnotatedCubeActor()
t = torus(5,1)
show(t, a)
Note that currently the show function is blocking.
Jupyter/JupterLab
There is also more limited support for displaying Workplane
, Sketch
, Assembly
,
Shape
in Jupyter and JupyterLab. This functionality is implemented using VTK.js.
from cadquery import *
Workplane().sphere(1).split(keepTop=True)