How to make cboreHole normal to back surface

94 views Asked by At

I am trying to create an angled bracket to be mounted onto a surface such that the counter-bored holes are normal to the back face, but start at the proper location on the front face.

I have this code:

backing = (
    housing_back_plane # this is just a workplane
    .rect(height,width).extrude(50, combine=False)
    .faces(">Y[-2]").workplane(invert=True).tag("front")
    .transformed(offset=cq.Vector(-height/2, -width/2, thickness),rotate=cq.Vector(5, -5, 0))
    .split(keepBottom=True)

    # Now lets try and put some holes in
    .workplaneFromTagged("front").workplane(invert=True)
    .rect(height - padding/1.5,width - padding/1.5,forConstruction=True)
    .vertices()
    .cboreHole(3.6, 5.5, 3)
)

Which generates the shape below. Note that while the holes are located correctly, the are normal to the front face, and I need them normal to the back face.

I am not sure how to combine the intended vertices with the angle of the back plane.

block with sloped back

1

There are 1 answers

0
JBCP On

I found that the cboreHole() function had an variable called boreDir that was not exposed. I duplicated the function and exposed boreDir as a parameter like this:

def _angledCBoreHole(
    self,
    diameter: float,
    cboreDiameter: float,
    cboreDepth: float,
    depth: Optional[float] = None,
    clean: bool = True,
    boreDir: cq.Vector = cq.Vector(0, 0, -1),
):
    # Taken from https://github.com/CadQuery/cadquery/blob/da6354fa787b2f4af6aa4fde5c4292894a1b629e/cadquery/cq.py#L2767
    if depth is None:
        depth = self.largestDimension()

    center = cq.Vector()
    # first make the hole
    hole = cq.Solid.makeCylinder(
        diameter / 2.0, depth, center, boreDir
    )  # local coordinates!

    # add the counter bore
    cbore = cq.Solid.makeCylinder(cboreDiameter / 2.0, cboreDepth, cq.Vector(), boreDir)
    r = hole.fuse(cbore)

    return self.cutEach(lambda loc: r.moved(loc), True, clean)

cq.Workplane.acboreHole = _angledCBoreHole

Then I found the example code here:

https://github.com/CadQuery/cadquery/issues/357#issuecomment-670009050

And used it to figure out how which normal I wanted to use (in my case the Y direction).

For now I manually hardcoded the values, so its:

    yDir = cq.Vector(-0, 0.0872, -0.9962)

    housing_back_plane
    .rect(height,width).extrude(50, combine=False)
    .faces(">Y[-2]").workplane(invert=True).tag("front")
    .transformed(offset=cq.Vector(-height/2, -width/2, thickness),rotate=cq.Vector(5, -5, 0)).tag("back")
    .split(keepBottom=True)

    # Now lets try and put some holes in
    .workplaneFromTagged("front").workplane(offset=0.3, invert=True)
    .rect(height - padding/1.5,width - padding/1.5,forConstruction=True)
    .vertices()
    .acboreHole(3.6, 5.6, 3.3, boreDir=yDir)

The only problem here is that I still don't understand how the stack works, so I get and print the directions after the plane is generated, which forces me to hard code the yDir for now.