gumyr / cq_warehouse

A cadquery parametric part collection
Apache License 2.0
107 stars 23 forks source link

[feature request] pockets that can prevent nuts from turning #39

Closed greyltc closed 2 years ago

greyltc commented 2 years ago

Like these ones: nut_capture image

greyltc commented 2 years ago

Here's some example code to consider

import cadquery as cq
import cq_warehouse.fastener as cqf
import cq_warehouse.extensions
import math

MM = 1

nut = cqf.HexNut(size='M6-1', fastener_type='iso4033')

fastener_assembly = cq.Assembly(None, name="plate")

plate_size = (50 * MM, 50 * MM, 20 * MM)
plate = (
    cq.Workplane("XY")
    .box(*plate_size, centered=(True, True, False))
    .faces(">Z")
    .workplane(offset=-nut.nut_thickness)
    .clearanceHole(fastener=nut, counterSunk=False, baseAssembly=fastener_assembly)
)

flat_to_flat = math.sin(60*math.pi/180)*nut.nut_diameter

# most manufacturable:
#plate = plate.faces(">Z").workplane().sketch().slot(flat_to_flat/2, flat_to_flat).finalize().cutBlind(-nut.nut_thickness)

# best use of space:
plate = plate.faces(">Z").workplane().sketch().rect(flat_to_flat,nut.nut_diameter, angle=90).vertices().fillet(nut.nut_diameter/4).finalize().cutBlind(-nut.nut_thickness)

if "show_object" in locals():
    show_object(plate, name="plate", options={"alpha": 0.8})
    show_object(fastener_assembly, name="fastener_assembly")

This example is maximally manufacturable, but not the best use of space around the nut.

image image

greyltc commented 2 years ago

Best space usage is

plate = plate.faces(">Z").workplane().sketch().rect(flat_to_flat,nut.nut_diameter, angle=90).vertices().fillet(nut.nut_diameter/4).finalize().cutBlind(-nut.nut_thickness)

giving image

gumyr commented 2 years ago

Completed with commit https://github.com/gumyr/cq_warehouse/commit/177e0c76f50cd4941b5da07b59aa8ed96f94305d