\n",
"\n"
],
"text/plain": [
""
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#parameter definitions\n",
"p_outerWidth = 100.0 #Outer width of box enclosure\n",
"p_outerLength = 150.0 #Outer length of box enclosure\n",
"p_outerHeight = 50.0 #Outer height of box enclosure\n",
"\n",
"p_thickness = 3.0 #Thickness of the box walls\n",
"p_sideRadius = 10.0 #Radius for the curves around the sides of the bo\n",
"p_topAndBottomRadius = 2.0 #Radius for the curves on the top and bottom edges of the box\n",
"\n",
"p_screwpostInset = 12.0 #How far in from the edges the screwposts should be place.\n",
"p_screwpostID = 4.0 #nner Diameter of the screwpost holes, should be roughly screw diameter not including threads\n",
"p_screwpostOD = 10.0 #Outer Diameter of the screwposts.\\nDetermines overall thickness of the posts\n",
"\n",
"p_boreDiameter = 8.0 #Diameter of the counterbore hole, if any\n",
"p_boreDepth = 1.0 #Depth of the counterbore hole, if\n",
"p_countersinkDiameter = 0.0 #Outer diameter of countersink. Should roughly match the outer diameter of the screw head\n",
"p_countersinkAngle = 90.0 #Countersink angle (complete angle between opposite sides, not from center to one side)\n",
"p_flipLid = True #Whether to place the lid with the top facing down or not.\n",
"p_lipHeight = 1.0 #Height of lip on the underside of the lid.\\nSits inside the box body for a snug fit.\n",
"\n",
"#outer shell\n",
"oshell = cq.Workplane(\"XY\").rect(p_outerWidth,p_outerLength).extrude(p_outerHeight + p_lipHeight)\n",
"\n",
"#weird geometry happens if we make the fillets in the wrong order\n",
"if p_sideRadius > p_topAndBottomRadius:\n",
" oshell.edges(\"|Z\").fillet(p_sideRadius)\n",
" oshell.edges(\"#Z\").fillet(p_topAndBottomRadius)\n",
"else:\n",
" oshell.edges(\"#Z\").fillet(p_topAndBottomRadius)\n",
" oshell.edges(\"|Z\").fillet(p_sideRadius)\n",
"\n",
"#inner shell\n",
"ishell = oshell.faces(\"Z\").workplane(-p_thickness)\\\n",
" .rect(POSTWIDTH,POSTLENGTH,forConstruction=True)\\\n",
" .vertices()\n",
"\n",
"for v in postCenters.all():\n",
" v.circle(p_screwpostOD/2.0).circle(p_screwpostID/2.0)\\\n",
" .extrude((-1.0)*(p_outerHeight + p_lipHeight -p_thickness ),True)\n",
"\n",
"#split lid into top and bottom parts\n",
"(lid,bottom) = box.faces(\">Z\").workplane(-p_thickness -p_lipHeight ).split(keepTop=True,keepBottom=True).all() #splits into two solids\n",
"\n",
"#translate the lid, and subtract the bottom from it to produce the lid inset\n",
"lowerLid = lid.translate((0,0,-p_lipHeight))\n",
"cutlip = lowerLid.cut(bottom).translate((p_outerWidth + p_thickness ,0,p_thickness - p_outerHeight + p_lipHeight))\n",
"\n",
"#compute centers for counterbore/countersink or counterbore\n",
"topOfLidCenters = cutlip.faces(\">Z\").workplane().rect(POSTWIDTH,POSTLENGTH,forConstruction=True).vertices()\n",
"\n",
"#add holes of the desired type\n",
"if p_boreDiameter > 0 and p_boreDepth > 0:\n",
" topOfLid = topOfLidCenters.cboreHole(p_screwpostID,p_boreDiameter,p_boreDepth,(2.0)*p_thickness)\n",
"elif p_countersinkDiameter > 0 and p_countersinkAngle > 0:\n",
" topOfLid = topOfLidCenters.cskHole(p_screwpostID,p_countersinkDiameter,p_countersinkAngle,(2.0)*p_thickness)\n",
"else:\n",
" topOfLid= topOfLidCenters.hole(p_screwpostID,(2.0)*p_thickness)\n",
"\n",
"#flip lid upside down if desired\n",
"if p_flipLid:\n",
" topOfLid.rotateAboutCenter((1,0,0),180)\n",
"\n",
"result =topOfLid.combineSolids(bottom)\n",
" \n",
"#return the combined result\n",
"result"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"