gumyr / cq_warehouse

A cadquery parametric part collection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

allow fastenerLocations to work with one assembly (i.e. to global coordinates)

gumyr opened this issue · comments

Added an example of how to do this (/examples/bolt_plates_together.py):

import cadquery as cq
from cq_warehouse.fastener import HexHeadScrew, PlainWasher, HexNutWithFlange
import cq_warehouse.extensions

MM = 1

# Create the fasteners used in this example
hex_bolt = HexHeadScrew(
    size="M6-1", length=20 * MM, fastener_type="iso4014", simple=False
)
flanged_nut = HexNutWithFlange(size="M6-1", fastener_type="din1665")
large_washer = PlainWasher(size="M6", fastener_type="iso7093")

# Create an empty Assembly to hold all of the fasteners
fastener_assembly = cq.Assembly(None, name="top")

# Create the top and bottom plates with holes
top_plate_size = (50 * MM, 100 * MM, 5 * MM)
bottom_plate_size = (100 * MM, 50 * MM, 5 * MM)
top_plate = (
    cq.Workplane("XY", origin=(0, 0, bottom_plate_size[2]))
    .box(*top_plate_size, centered=(True, True, False))
    .faces(">Z")
    .workplane()
    .clearanceHole(
        fastener=hex_bolt,
        washers=[large_washer],
        baseAssembly=fastener_assembly,
        counterSunk=False,
    )
)
bottom_plate = (
    cq.Workplane("XY")
    .box(*bottom_plate_size, centered=(True, True, False))
    .pushFastenerLocations(
        fastener=large_washer,
        baseAssembly=fastener_assembly,
        offset=-(top_plate_size[2] + bottom_plate_size[2]),
        flip=True,
    )
    .clearanceHole(
        fastener=flanged_nut,
        baseAssembly=fastener_assembly,
        counterSunk=False,
    )
)
print(fastener_assembly.fastenerQuantities())

if "show_object" in locals():
    show_object(
        top_plate, name="top_plate", options={"alpha": 0.8, "color": (170, 0, 255)}
    )
    show_object(
        bottom_plate, name="bottom_plate", options={"alpha": 0.8, "color": (255, 85, 0)}
    )
    show_object(fastener_assembly, name="fastener_assembly")

which generates:
image