1- import cadquery as cq
2-
3- # Parameter definitions
4- p_outerWidth = 100.0 # Outer width of box enclosure
5- p_outerLength = 150.0 # Outer length of box enclosure
6- p_outerHeight = 50.0 # Outer height of box enclosure
7-
8- p_thickness = 3.0 # Thickness of the box walls
9- p_sideRadius = 10.0 # Radius for the curves around the sides of the bo
10- p_topAndBottomRadius = 2.0 # Radius for the curves on the top and bottom edges
11-
12- p_screwpostInset = 12.0 # How far in from the edges the screwposts should be
13- p_screwpostID = 4.0 # Inner diameter of the screwpost holes, should be roughly screw diameter not including threads
14- p_screwpostOD = 10.0 # Outer diameter of the screwposts. Determines overall thickness of the posts
15-
16- p_boreDiameter = 8.0 # Diameter of the counterbore hole, if any
17- p_boreDepth = 1.0 # Depth of the counterbore hole, if
18- p_countersinkDiameter = 0.0 # Outer diameter of countersink. Should roughly match the outer diameter of the screw head
19- p_countersinkAngle = 90.0 # Countersink angle (complete angle between opposite sides, not from center to one side)
20- p_lipHeight = 1.0 # Height of lip on the underside of the lid. Sits inside the box body for a snug fit.
21-
22- # Outer shell
23- oshell = cq .Workplane ("XY" ).rect (p_outerWidth , p_outerLength ) \
24- .extrude (p_outerHeight + p_lipHeight )
25-
26- # Weird geometry happens if we make the fillets in the wrong order
1+ # parameter definitions
2+ p_outerWidth = 100.0 #Outer width of box enclosure
3+ p_outerLength = 150.0 #Outer length of box enclosure
4+ p_outerHeight = 50.0 #Outer height of box enclosure
5+
6+ p_thickness = 3.0 #Thickness of the box walls
7+ p_sideRadius = 10.0 #Radius for the curves around the sides of the box
8+ p_topAndBottomRadius = 2.0 #Radius for the curves on the top and bottom edges of the box
9+
10+ p_screwpostInset = 12.0 #How far in from the edges the screw posts should be place.
11+ p_screwpostID = 4.0 #Inner Diameter of the screw post holes, should be roughly screw diameter not including threads
12+ p_screwpostOD = 10.0 #Outer Diameter of the screw posts.\nDetermines overall thickness of the posts
13+
14+ p_boreDiameter = 8.0 #Diameter of the counterbore hole, if any
15+ p_boreDepth = 1.0 #Depth of the counterbore hole, if
16+ p_countersinkDiameter = 0.0 #Outer diameter of countersink. Should roughly match the outer diameter of the screw head
17+ p_countersinkAngle = 90.0 #Countersink angle (complete angle between opposite sides, not from center to one side)
18+ p_flipLid = True #Whether to place the lid with the top facing down or not.
19+ p_lipHeight = 1.0 #Height of lip on the underside of the lid.\nSits inside the box body for a snug fit.
20+
21+ # outer shell
22+ oshell = cq .Workplane ("XY" ).rect (p_outerWidth ,p_outerLength ).extrude (p_outerHeight + p_lipHeight )
23+
24+ # weird geometry happens if we make the fillets in the wrong order
2725if p_sideRadius > p_topAndBottomRadius :
28- oshell .edges ("|Z" ).fillet (p_sideRadius )
29- oshell .edges ("#Z" ).fillet (p_topAndBottomRadius )
26+ oshell = oshell .edges ("|Z" ).fillet (p_sideRadius )
27+ oshell = oshell .edges ("#Z" ).fillet (p_topAndBottomRadius )
3028else :
31- oshell .edges ("#Z" ).fillet (p_topAndBottomRadius )
32- oshell .edges ("|Z" ).fillet (p_sideRadius )
29+ oshell = oshell .edges ("#Z" ).fillet (p_topAndBottomRadius )
30+ oshell = oshell .edges ("|Z" ).fillet (p_sideRadius )
3331
34- # Inner shell
35- ishell = oshell .faces ("<Z" ).workplane (p_thickness , True )\
36- .rect ((p_outerWidth - 2.0 * p_thickness ), (p_outerLength - 2.0 * p_thickness ))\
37- .extrude ((p_outerHeight - 2.0 * p_thickness ), False ) # Set combine false to produce just the new boss
38- ishell .edges ("|Z" ).fillet (p_sideRadius - p_thickness )
32+ # inner shell
33+ ishell = (oshell .faces ("<Z" ).workplane (p_thickness ,True )
34+ .rect ((p_outerWidth - 2.0 * p_thickness ),(p_outerLength - 2.0 * p_thickness ))
35+ .extrude ((p_outerHeight - 2.0 * p_thickness ),False ) #set combine false to produce just the new boss
36+ )
37+ ishell = ishell .edges ("|Z" ).fillet (p_sideRadius - p_thickness )
3938
40- # Make the box outer box
39+ # make the box outer box
4140box = oshell .cut (ishell )
4241
43- # Make the screwposts
44- POSTWIDTH = (p_outerWidth - 2.0 * p_screwpostInset )
45- POSTLENGTH = (p_outerLength - 2.0 * p_screwpostInset )
46-
47- postCenters = box .faces (">Z" ).workplane (- p_thickness )\
48- .rect (POSTWIDTH , POSTLENGTH , forConstruction = True )\
49- .vertices ()
42+ # make the screw posts
43+ POSTWIDTH = (p_outerWidth - 2.0 * p_screwpostInset )
44+ POSTLENGTH = (p_outerLength - 2.0 * p_screwpostInset )
5045
51- for v in postCenters .all ():
52- v .circle (p_screwpostOD / 2.0 ).circle (p_screwpostID / 2.0 )\
53- .extrude ((- 1.0 ) * ((p_outerHeight + p_lipHeight ) - (2.0 * p_thickness )), True )
46+ box = (box .faces (">Z" ).workplane (- p_thickness )
47+ .rect (POSTWIDTH ,POSTLENGTH ,forConstruction = True )
48+ .vertices ().circle (p_screwpostOD / 2.0 ).circle (p_screwpostID / 2.0 )
49+ .extrude ((- 1.0 )* (p_outerHeight + p_lipHeight - p_thickness ),True ))
5450
55- # Split lid into top and bottom parts
56- (lid , bottom ) = box .faces (">Z" ).workplane (- p_thickness - p_lipHeight ).split (keepTop = True , keepBottom = True ).all ()
51+ # split lid into top and bottom parts
52+ (lid ,bottom ) = box .faces (">Z" ).workplane (- p_thickness - p_lipHeight ).split (keepTop = True ,keepBottom = True ).all () #splits into two solids
5753
58- # Translate the lid, and subtract the bottom from it to produce the lid inset
59- lowerLid = lid .translate ((0 , 0 , - p_lipHeight ))
60- cutlip = lowerLid .cut (bottom ).translate ((p_outerWidth + p_thickness , 0 , p_thickness - p_outerHeight + p_lipHeight ))
54+ # translate the lid, and subtract the bottom from it to produce the lid inset
55+ lowerLid = lid .translate ((0 ,0 , - p_lipHeight ))
56+ cutlip = lowerLid .cut (bottom ).translate ((p_outerWidth + p_thickness , 0 , p_thickness - p_outerHeight + p_lipHeight ))
6157
62- # Compute centers for counterbore/countersink or counterbore
63- topOfLidCenters = cutlip .faces (">Z" ).workplane ().rect (POSTWIDTH , POSTLENGTH , forConstruction = True ).vertices ()
58+ # compute centers for counterbore/countersink or counterbore
59+ topOfLidCenters = cutlip .faces (">Z" ).workplane ().rect (POSTWIDTH ,POSTLENGTH ,forConstruction = True ).vertices ()
6460
65- # Add holes of the desired type
61+ # add holes of the desired type
6662if p_boreDiameter > 0 and p_boreDepth > 0 :
67- topOfLid = topOfLidCenters .cboreHole (p_screwpostID , p_boreDiameter , p_boreDepth , (2.0 ) * p_thickness )
63+ topOfLid = topOfLidCenters .cboreHole (p_screwpostID ,p_boreDiameter ,p_boreDepth ,(2.0 )* p_thickness )
6864elif p_countersinkDiameter > 0 and p_countersinkAngle > 0 :
69- topOfLid = topOfLidCenters .cskHole (p_screwpostID , p_countersinkDiameter , p_countersinkAngle , (2.0 ) * p_thickness )
65+ topOfLid = topOfLidCenters .cskHole (p_screwpostID ,p_countersinkDiameter ,p_countersinkAngle ,(2.0 )* p_thickness )
7066else :
71- topOfLid = topOfLidCenters .hole (p_screwpostID , 2.0 * p_thickness )
67+ topOfLid = topOfLidCenters .hole (p_screwpostID ,( 2.0 ) * p_thickness )
7268
73- # Return the combined result
74- result = topOfLid .combineSolids (bottom )
69+ # flip lid upside down if desired
70+ if p_flipLid :
71+ topOfLid = topOfLid .rotateAboutCenter ((1 ,0 ,0 ),180 )
7572
76- # Displays the result of this script
77- show_object ( result )
73+ # return the combined result
74+ result = topOfLid . union ( bottom )
0 commit comments