In [61]:
import cadquery as cq
from cadquery import Assembly
# Parameters
box_length = 50.0 # Length of the box
box_width = 50.0 # Width of the box
box_height = 20.0 # Height of the box
button_diameter = 10.0 # Diameter of the buttons
button_height = 2.0 # Height of the buttons
button_spacing = 12.0 # Spacing between buttons
button_padding=-2.5
button_slope=5
up_button = -box_length/2+button_spacing
# Create a box
left_module = cq.Workplane("XY").box(box_length, box_width, box_height)
# Create a button
def create_button(x, y):
return (cq.Workplane("XY")
.center(x, y)
.circle(button_diameter/2)
.extrude(button_height))
# Calculate positions for the four buttons
positions = [
(button_padding+button_diameter+button_spacing*0, button_slope),
(button_padding+button_diameter+button_spacing*1, button_slope*2),
(button_padding+button_diameter+button_spacing*2, button_slope),
(button_padding+button_diameter+button_spacing*3, up_button)
]
# Place buttons on top of the box
for pos in positions:
left_module = left_module.union(
create_button(pos[0], pos[1]).translate((-box_length/2, 0, box_height/2))
)
# Show the result (if using a Jupyter Notebook or CadQuery Editor)
left_module
Out[61]:
In [65]:
# Parameters
base_length = box_length*3 # Length of the box
base_width = box_width*1.5 # Width of the box
base_height = box_height*2 # Height of the box
# Create base
base = cq.Workplane("XY").box(base_length, base_width, base_height)
base
Out[65]:
In [63]:
# Create a box
right_module = cq.Workplane("XY").box(box_length, box_width, box_height)
# Calculate positions for the four buttons
positions = [
(button_padding+button_diameter+button_spacing*0, button_spacing/2+button_slope*0.5),
(button_padding+button_diameter+button_spacing*1, button_spacing/2+button_slope*1),
(button_padding+button_diameter+button_spacing*2, button_spacing/2+button_slope*0.5),
(button_padding+button_diameter+button_spacing*3, button_spacing/2+button_slope*0),
(button_padding+button_diameter+button_spacing*0, -button_spacing/2+button_slope*0.5),
(button_padding+button_diameter+button_spacing*1, -button_spacing/2+button_slope*1),
(button_padding+button_diameter+button_spacing*2, -button_spacing/2+button_slope*0.5),
(button_padding+button_diameter+button_spacing*3, -button_spacing/2+button_slope*0)
]
# Place buttons on top of the box
for pos in positions:
right_module = right_module.union(
create_button(pos[0], pos[1]).translate((-box_length/2, 0, box_height/2))
)
# Show the result (if using a Jupyter Notebook or CadQuery Editor)
right_module
Out[63]:
In [84]:
# Parameters
box_padding=10
# Create assembly
controller = Assembly()
# Add parts to the assembly
controller.add(left_module, name="left", loc=cq.Location(cq.Vector(-box_width*0.5-box_padding, 0, box_height/2)))
controller.add(right_module, name="right", loc=cq.Location(cq.Vector(box_width*0.5+box_padding, 0, box_height/2)))
controller.add(base, name="base", loc=cq.Location(cq.Vector(0, 0, 0)))
# Display controller
controller
Out[84]:
In [ ]: