cadquery-freecad-module/Examples/Ex003_Pillow_Block_With_Counterbored_Holes.py
2017-09-15 22:13:39 -04:00

35 lines
1.8 KiB
Python

import cadquery as cq
# These can be modified rather than hardcoding values for each dimension.
length = 80.0 # Length of the block
height = 60.0 # Height of the block
thickness = 10.0 # Thickness of the block
center_hole_dia = 22.0 # Diameter of center hole in block
cbore_hole_diameter = 2.4 # Bolt shank/threads clearance hole diameter
cbore_diameter = 4.4 # Bolt head pocket hole diameter
cbore_depth = 2.1 # Bolt head pocket hole depth
# Create a 3D block based on the dimensions above and add a 22mm center hold
# and 4 counterbored holes for bolts
# 1. Establishes a workplane that an object can be built on.
# 1a. Uses the X and Y origins to define the workplane, meaning that the
# positive Z direction is "up", and the negative Z direction is "down".
# 2. The highest(max) Z face is selected and a new workplane is created on it.
# 3. The new workplane is used to drill a hole through the block.
# 3a. The hole is automatically centered in the workplane.
# 4. The highest(max) Z face is selected and a new workplane is created on it.
# 5. A for-construction rectangle is created on the workplane based on the
# block's overall dimensions.
# 5a. For-construction objects are used only to place other geometry, they
# do not show up in the final displayed geometry.
# 6. The vertices of the rectangle (corners) are selected, and a counter-bored
# hole is placed at each of the vertices (all 4 of them at once).
result = cq.Workplane("XY").box(length, height, thickness) \
.faces(">Z").workplane().hole(center_hole_dia) \
.faces(">Z").workplane() \
.rect(length - 8.0, height - 8.0, forConstruction=True) \
.vertices().cboreHole(cbore_hole_diameter, cbore_diameter, cbore_depth)
# Displays the result of this script
show_object(result)