I have a simple question about making plugins that involve both extrusions
and cuts.
Imagine you want a plugin for a "bossed" hole: drill a hole in a part, and
add a circular "boss" around the hole.
I currently have the following:
from __future__ import division
import cadquery as cq
def bossedHole(self, diameter, bossDia,
depth=None, nutAngle=0, clean=True):
if depth is None:
depth = self.largestDimension()
def _makeHole(center):
# center is in local coordinates
boreDir = cq.Vector(0, 0, -1)
# first make the hole # local coords!
hole = cq.Solid.makeCylinder(diameter/2.0, depth, center, boreDir)
return hole
def _makeBoss(center):
# center is in local coordinates
boreDir = cq.Vector(0, 0, -1)
# make the boss # local coords!
boss = cq.Solid.makeCylinder(bossDia/2.0, depth, center, boreDir)
return boss
r = self.eachpoint(_makeBoss, True).combineSolids()
r = self.cutEach(_makeHole, True, clean)
return r
# link the plugin into cadQuery
cq.Workplane.bossedHole = bossedHole
result = cq.Workplane("XY").box(10, 10, 2)
result = result.faces("<Z").workplane() \
.rect(5, 5).vertices() \
.bossedHole(2, 4, 4)
show_object(result, options={"rgba":(204, 204, 204, 0.0)})
The basic gist is:
- For each point, from the bottom side:
- Extrude the boss right though the part from the bottom to the
desired depth
- Drill the hole from the bottom to the same depth
This is actually what I wanted in this case, but it occurred to me that I
don't know how to do the following operation from the top face:
- For each point, from the top side:
- Extrude the boss upwards by "z" mm
- Drill a hole down though the boss *and* the part to a certain depth
Is that possible within a single plugin?
Cheers,
John
Hey John,
import cadquery as cq
def make_holes_with_collars(self, fi,w,h,d):
depth = d-h
def _hole(pnt):
boreDir = cq.Vector(0, 0, -1)
hole = cq.Solid.makeCylinder(fi, depth, pnt, boreDir) # local coordinates!
return hole
def _collar(pnt):
extDir = cq.Vector(0, 0, h)
w1 = cq.Wire.makeCircle(fi,pnt,extDir)
w2 = cq.Wire.makeCircle(fi+w,pnt,extDir)
return cq.Solid.extrudeLinear(w2,[w1],extDir)
base = self.cutEach(_hole,True)
collars = self.eachpoint(_collar,True)
return base.union(collars)
cq.Workplane.make_holes_with_collars = make_holes_with_collars
result = cq.Workplane("XY" ).box(5,5,3).edges("|Z").fillet(0.125).\
faces('>Z').workplane().rect(3,3,forConstruction=True).vertices().\
make_holes_with_collars(.5,.2,.7,2)
show_object(result)