Refactored usb hub module

This commit is contained in:
Roberto Alsina 2023-03-20 15:04:19 -03:00
parent 9bdabfdd98
commit cdf2e33f64
6 changed files with 93 additions and 63 deletions

View File

@ -12,7 +12,7 @@ holes = [
{ {
"x": 0, "x": 0,
"y": 4, "y": 4,
"shape": cq.Sketch().trapezoid(17, 2, 90, mode="a").fillet(2), "shape": cq.Sketch().trapezoid(17, 5, 90, mode="a").fillet(2),
}, },
] ]

Binary file not shown.

Binary file not shown.

View File

@ -153,31 +153,17 @@ def model():
# Now the basic box shape is in place, start adding things # Now the basic box shape is in place, start adding things
# and cutting holes. # and cutting holes.
# Hole for USB hub in the back model = usb_hub.add(
for hole in usb_hub.holes: model=model,
model = punch_hole( width=width,
model=model, height=height,
face=">Y", thickness=thickness,
w=width, bottom_face="<Z",
h=thickness, back_face=">Y",
x_offset=usb_offset + shell_t + usb_hub.holes[0]["width"] / 2, offset_x=width - usb_offset,
y_offset=shell_t, offset_y=0,
hole=hole, shell_t=shell_t,
depth=shell_t, )
)
# USB hub holder
for element in usb_hub.elements:
model = extrude_shape(
model=model,
face="<Z",
w=width,
h=height,
x_offset=width - usb_offset - shell_t - +usb_hub.holes[0]["width"] / 2,
y_offset=shell_t + element["y"],
shape=element["shape"],
height=-(element["height"] + shell_t),
)
# Hole for audio in right side # Hole for audio in right side
model = audio_plug.add( model = audio_plug.add(
@ -222,43 +208,43 @@ def model():
if __name__ == "__main__": if __name__ == "__main__":
left_cutout = cq.Sketch().polygon( # left_cutout = cq.Sketch().polygon(
[(0, 0), (width / 2, 0), (width / 2, -height), (0, -height), (0, 0)], # [(0, 0), (width / 2, 0), (width / 2, -height), (0, -height), (0, 0)],
mode="a", # mode="a",
) # )
right_side = ( # right_side = (
model() # model()
.faces("<Z") # .faces("<Z")
.workplaneFromTagged("mid_height") # .workplaneFromTagged("mid_height")
.transformed(offset=cq.Vector(0, 0, -thickness / 2)) # .transformed(offset=cq.Vector(0, 0, -thickness / 2))
.center(-width / 2, height / 2) # .center(-width / 2, height / 2)
.placeSketch(left_cutout) # .placeSketch(left_cutout)
.cutBlind(100) # .cutBlind(100)
) # )
exporters.export(right_side, "right_side.stl") # exporters.export(right_side, "right_side.stl")
right_cutout = cq.Sketch().polygon( # right_cutout = cq.Sketch().polygon(
[ # [
(width / 2, 0), # (width / 2, 0),
(width, 0), # (width, 0),
(width, -height), # (width, -height),
(width / 2, -height), # (width / 2, -height),
(width / 2, 0), # (width / 2, 0),
], # ],
mode="a", # mode="a",
) # )
left_side = ( # left_side = (
model() # model()
.faces("<Z") # .faces("<Z")
.workplaneFromTagged("mid_height") # .workplaneFromTagged("mid_height")
.transformed(offset=cq.Vector(0, 0, -thickness / 2)) # .transformed(offset=cq.Vector(0, 0, -thickness / 2))
.center(-width / 2, height / 2) # .center(-width / 2, height / 2)
.placeSketch(right_cutout) # .placeSketch(right_cutout)
.cutBlind(100) # .cutBlind(100)
) # )
exporters.export(left_side, "left_side.stl") # exporters.export(left_side, "left_side.stl")
exporters.export(model(), "model.stl") exporters.export(model(), "model.stl")

Binary file not shown.

View File

@ -1,5 +1,7 @@
import cadquery as cq import cadquery as cq
from utils import punch_hole2, extrude_shape, extrude_shape2
# Measurements for my USB hub, YMMV # Measurements for my USB hub, YMMV
# The hole is for a USB-A plug, y is measured in the hub # The hole is for a USB-A plug, y is measured in the hub
@ -11,9 +13,7 @@ holes = [
{ {
"x": 0, "x": 0,
"y": 4, "y": 4,
"height": 5.5, "shape": cq.Sketch().trapezoid(13, 5, 90, mode="a").vertices().fillet(2),
"width": 13,
"fillet": 2,
}, },
] ]
@ -31,3 +31,47 @@ elements = [
"height": 8, "height": 8,
} }
] ]
def add(
*,
model,
width,
height,
thickness,
offset_x,
offset_y,
bottom_face,
back_face,
shell_t
):
# USB Hub extrusions
if bottom_face:
for element in elements:
model = extrude_shape(
model=model,
face=bottom_face,
w=width,
h=height,
x_offset=offset_x + element["x"],
y_offset=shell_t + offset_y + element["y"],
shape=element["shape"],
height=-(element["height"] + shell_t),
)
# Holes
if back_face:
for hole in holes:
model = punch_hole2(
model=model,
face=back_face,
w=width,
h=thickness,
x_offset=width - offset_x,
y_offset=shell_t,
hole=hole,
depth=shell_t,
)
return model