If you use conda you might try creating a new environment and install using conda directly:
conda create -n cadquery-master
conda install -c cadquery -c conda-forge cadquery=master
Or if you want both cq-editor and cadquery:
conda create -n cqgui-master
conda install -c cadquery -c conda-forge cq-editor=master
This will allow you to update a Conda environment.
conda remove cq-editor
conda clean --all --force-pkgs-dirs
conda install --force-reinstall -c conda-forge -c cadquery cq-editor=master
result = ( cq.Workplane("XY") .box(2.0, 2.0, 0.5) .faces(">Y").wires().toPending().offset2D(-.1) .transformed(rotate=(-90,0,0)).extrude(.5) )
import sys
from OCP.BRepPrimAPI import BRepPrimAPI_MakeBox
from cq_editor.widgets import viewer as cqv
import cadquery as cq
app = cqv.QApplication(sys.argv)
viewer = cqv.OCCViewer()
dlg = cqv.QDialog()
dlg.setFixedHeight(400)
dlg.setFixedWidth(600)
cqv.layout(dlg,(viewer,),dlg)
dlg.show()
#box = BRepPrimAPI_MakeBox(20,20,30)
box = cq.Workplane("XY").box(20,20,30).val().wrapped
box_ais = cqv.AIS_ColoredShape(box)
viewer.display(box_ais)
sys.exit(app.exec_())
This helper can also be used in conjunction with this.
.each(lambda p: p.scale(25.4))
res = cq.Workplane().rect(1,1).rect(3,3).consolidateWires()
Put this at the top of your script and show_object() will have no effect when running outside of CQ-editor:
if 'show_object' not in globals():
def show_object(*args, **kwargs):
pass
If you want to use show_object inside non-main modules you can do this (it's a bit of a hack though)
# (main module)
import my_other_module
my_other_module.show_object = show_object
res = (
cq.Workplane()
.ellipse(10,5)
.workplane(10)
.ellipse(8,10)
.loft()
)
res2 = res.faces('>Z')
show_object(res,'res',options=dict(alpha=0.9))
show_object(res2,'res2',options=dict(alpha=0.1,color=(1.,0,0)))
stand.faces('>Z').edges('|(1,1,0) or |(1,-1,0)')
conda create --dry-run --json -n dummy <package>
L = Ltrans*Lrot1 * Lrto2
import cadquery as cq
path = cq.Workplane().slot2D(20,5)
sweep = cq.Workplane("YZ", origin = (0,2.5)).slot2D(3,2,90).sweep(path)
revolve = cq.Workplane("XZ").move(10,-10).slot2D(2.5,2).wire().revolve(360,(0,0),(0,1))
Source: Discord
sudo mcopy /lib/libstdc++.so.6 ~/.conda/envs/cqgui/lib
Source: Google Groups
a = cq.Workplane("XY").rect(xLen=1, yLen=2).extrude(5)
b = cq.Workplane("XY").rect(xLen=2, yLen=1).extrude(10)
assembly = (
cq.Assembly(a, name="a", color=cq.Color("red"))
.add(b, name="b", color=cq.Color("green"))
)
assembly.constrain(
"a",
cq.Vertex.makeVertex(3, 0, 0),
"b",
b.vertices("<X and <Y and <Z").val(),
"Point",
)
assembly.constrain("a@faces@>X", "b@faces@<X", "Axis")
assembly.solve()
show_object(assembly)
height = 60.0
describe_parameter(height, '30.0 140.0')
width = 80.0
describe_parameter(width, '20.0 100.0')
Source: GitHub
Sample code is here
Source: Google Groups
import cadquery as cq
s1 = (
cq.Sketch()
.rect(30, 40)
.rect(10, 10, mode="s", tag="rectcut")
.vertices(">X", tag="rectcut")
.fillet(1)
.vertices("<X", tag="rectcut")
.fillet(2)
)
r = cq.Workplane().placeSketch(s1).extrude(10)
Source: Discord
If there is an error similar to this:
Error loading Python lib '/Users/me/Downloads/CQ-editor-MacOS/CQ-editor/libpython3.8.dylib': dlopen: dlopen(/Users/me/Downloads/CQ-editor-MacOS/CQ-editor/libpython3.8.dylib, 10): no suitable image found. Did find:
/Users/me/Downloads/CQ-editor-MacOS/CQ-editor/libpython3.8.dylib: code signature in (/Users/me/Downloads/CQ-editor-MacOS/CQ-editor/libpython3.8.dylib) not valid for use in process using Library Validation: library load disallowed by system policy
Try this form:
xattr -r -d com.apple.quarantine path/to/CQ-editor-MacOS
Source GitHub
# Font that is offset and not symmetrical in all axes
text = cq.Workplane().text("X", 12, 1, False, True)
# Get the bounding box, which will have xmin, ymin, etc in local coordinates
bbox = text.val().BoundingBox()
# Alernative way to get the center that is not needed
# cen = text.val().CenterOfBoundBox()
# Move the bounding box and draw a rect to represent it (this was displayed in CQ-editor)
bb = cq.Workplane().moveTo(bbox.center.x, bbox.center.y).rect(bbox.xmax-bbox.xmin, bbox.ymax-bbox.ymin).extrude(1)
Source Google Groups
pts = [
(1, 1, 1),
(1, 2, 2),
(1, 3, 3),
]
p = cq.Workplane("XY").spline(pts, includeCurrent=True)
dire = p.val().tangentAt(0)
plane = cq.Plane((0,0,0), normal=dire)
s = cq.Workplane(plane).circle(1).sweep(p)
Source GitHub
Paired with the helper shown here.
from multiprocessing import Pool
import cadquery as cq
from cq_serialize import register as register_cq_helper
register_cq_helper()
def make_box(size: float):
return cq.Workplane("XY").box(size, size, size).findSolid()
with Pool() as p:
boxes = p.map(make_box, range(1, 10))
Source GitHub
You have to add single quotes around the package because of the way zsh interprets [
and ]
.
pip install 'cadquery[ipython]==2.2.0b0'
Source GitHub
If you see ShapeUpgrade_UnifySameDomain
in a CadQuery script's trace, then the issue is likely related to clean=True
. Try clean=False
instead.
Source Google Groups
head = (
cq.Workplane("XZ")
.lineTo(head_width2, 0)
.ellipseArc(head_width2, head_height, angle1=0, angle2=90)
.close()
.revolve(360, axisStart=(0, 0, 0), axisEnd=(0, 1, 0))
.cut(sock)
.cut(sock.translate((1.5 * eye_offset, 0, 0)))
.faces("not %Plane")
.edges("not <Z")
.edges("not <Y")
.chamfer(1)
)
Source Google Groups
s = cq.Sketch().circle(1)
cq.exporters.export(s.faces().val(), "out.svg", opt={"projectionDir": (0, 0, 1)})
Source GitHub
# Create the plate and show it in CQ-editor (if we are executing it that way)
if 'show_object' in globals():
plate = generate()
show_object(plate)
Source GitHub
$ arch -x86_64 brew install miniconda
$ arch -x86_64 conda install -c cadquery -c conda-forge cadquery=master
$ arch -x86_64 conda install -c cadquery -c conda-forge cq-editor=master
$ arch -x86_64 /opt/homebrew/Caskroom/miniconda/base/bin/python
Source GitHub
- Fixed fixes all 6 degrees of freedom and FixedPoint fixes only 3 translational degrees of freedom. Source GitHub
from cadquery import *
c = Workplane().cylinder(5,1)
l = Workplane().moveTo(5,0).lineTo(-5,0)
res = c.intersect(l).edges().val()
start = res.startPoint()
stop = res.endPoint()
lengt = res.Length()
Source GitHub
# Install cadquery and any other packages you are developing with `pip install -e .` while in those repo directories
# Install cadquery deps manually.
# cd into local copy of CQ-editor repo
pip install -e .
Source (kind of) GitHub
- Work in 2D as long as possible
- Avoid boolean ops
- If you must use boolean ops, do not use them in loops
- If possible, use bool ops with glue=True
- Turn off clean (set clean=False)
Source Google Groups
import OCP
w = OCP.STEPControl.STEPControl_Writer()
OCP.Interface.Interface_Static.SetCVal_s("write.step.unit","UM")
Source Google Groups
Be sure to set the number of threads before importing CadQuery.
import OCP
pool = OCP.OSD.OSD_ThreadPool.DefaultPool_s(1)
import cadquery as cq
Source GitHub