import cadquery as cq
from cq_warehouse.fastener import SocketHeadCapScrew
# Create the screws that will fasten the plates together
cap_screw = SocketHeadCapScrew(
size="M2-0.4", length=5, fastener_type="iso4762", simple=False
)
# Two assemblies are required - the top will contain the screws
top_plate_assembly = cq.Assembly(None, name="top_plate_assembly")
base_plate_assembly = cq.Assembly(None, name="base_plate_assembly")
# Create the top plate and add clearance holes for the screws
top_plate = (
cq.Workplane()
.box(10, 10, 1, centered=(True, True, False))
.faces(">Z")
.workplane()
.pushPoints([(3, 3), (-3, -3)])
.clearanceHole(
fastener=cap_screw, counterSunk=False, baseAssembly=top_plate_assembly
)
)
# Define the location of the top plate relative to the base plate
top_plate_location = cq.Vector(25, 0, 1)
# Extract the bolt locations that will be used to create holes in the base plate
base_bolt_hole_locations = [
cq.Vector(screw.loc.toTuple()[0]) + top_plate_location
for screw in top_plate_assembly.children
]
# Add the top plate to the top assembly so it can be placed with the screws
top_plate_assembly.add(top_plate)
# Add the top plate and screws to the base assembly
base_plate_assembly.add(
top_plate_assembly, name="top_plate_assembly", loc=cq.Location(top_plate_location)
)
# Create the base plate with tap holes that align with the top plate
base_plate = (
cq.Workplane()
.box(65, 100, 1, centered=(True, True, False))
.faces(">Z")
.workplane()
.pushPoints(base_bolt_hole_locations)
.tapHole(fastener=cap_screw, counterSunk=False)
)
# Complete the base plate assembly by adding the top assembly and base plate
base_plate_assembly.add(base_plate, name="base_plate")
if "show_object" in locals():
show_object(top_plate, name="top_plate")
show_object(base_plate, name="base_plate")
show_object(base_plate_assembly, name="plate_assembly")