CadQuery is a code based cad library much like OpenSCAD but based in python. Unlike OpenSCAD the modeling uses OpenCascade on the back end. Therefor the modeling experience is closer to other BRep cad software packages such as Fusion 360 or Solidworks. This enclosure is my first project using the library.
One cool thing is that files can be imported and exported as STEP files. This means that the PCBs designed in KiCAD can be imported and designed into the enclosure.
I recommend installing CQ-editor. It is a small IDE that has CadQuery bundled and can display and export your model directly within the IDE. The official github is here: https://github.com/CadQuery/CQ-editor
At the top of the file there is a collection of Global variables are passed into the code below to generate the enclosure.
#Secect What Componets to Make
makeTop=True
makeBottom=True
makeFront=True
makeBack=True
In the code above, coorisponds to the parts to be generated. For example set makeTop to True and the other variables to False to only make the top of the enclosure.
#overall shell Dims
height=40 #Height of the enclosure
width=170 #Width of the enclosure
length=90 #Length of enclsosure
thick=2 #Thickness of the walls
roundingRad=3 #size of the fillets
grooveThick=2 #Thickness of the front and back panels
grooveTol=0.6 #Tolerance or extra slop given to panel groove
Change the values above to change the size of the enclosure. Note all dimensions are in millimeters.
#Dims of the mounting feet on the bottom
needMounts=True
mountLenPad=8
mountT=thick
mountHoleDia=5
The code above affects the size of the side mounting pads. Set “needMounts” to False to remove the side mounting feet completely.
#Dims of the side tabs on the Bottom
tabW=10
tabH=8
tabT=2
tabHoleDia=2
These variables describe the size of the mounting tabs that come up from the bottom piece of the enclosure so that the top piece can screw to it.
#PCB Mounting Posts
#locations of the PCB Posts [(x,y),(x,y)]
pcbMLocs=[(-66.675+5.715,46.79-27.94-12),(-66.675+5.715,21.79-27.94-12),
(+66.675-5.715,46.79-27.94-12),(+66.675-5.715,21.79-27.94-12)]
pcbMDia=5
pcbHoleDia=2
pcbMHeight=8
If you need mounting posts you can have an arbitrary number of them by filling out the array. the PCB is located from the center of the enclosure. If no PCB mounts are needed change pcbMlocs to an empty array.
#Bottom Vents
botSideVents=False
#Top Vents
topSideVents=False
topTopVents=True
Set True of False depending on if you want enclosure vents.
##Fill out for holes on the front card of the enclosure#####
#locations for holes are defiined as [(x_loc,y_loc.dia),(x,y.dia)]
frontHoles=[]
#locations for rectangels are defined as [(x_loc,y_loc,width,length)]
frontRects=[]
#text [(x,y,thick,fontsize,text)]
frontTexts=[]
##Fill out for hols and text on the back card of the enclosure##
#locations for holes are defiined as [(x_loc,y_loc.dia),(x,y.dia)]
backHoles=[]
#locations for rectangels are defined as [(x_loc,y_loc,width,length)]
backRects=[(-16,-2,31,10),(-49,-2,31,10),
(17,-2,31,10),(50,-2,31,10)]
#text [(x,y,thick,fontsize,text)]
backTexts=[(-49,7,1,5,"MFC 1"),(-16,7,1,5,"MFC 2"),
(17,7,1,5,"MFC 3"),(50,7,1,5,"MFC 4"),(0,13,1,7,"Alicat Mass Flow Meters")]
Define the location and sizes of the front hole cutouts on the front and back panel. In this model it supports circles and squares of any size. Text can be also added to the front and back panels by modifying the arrays above.
Well that is it. I hope that this code can be useful to anyone who needs it and let me know if you have any recommendations.
The author marked this model as their own original creation.