This OpenSCAD design lets you define the number of AA and/or AAA batteries for the case. Just select the number of rows of each battery type and the number of batteries per row. There are other adjustable parameters for the border width around the battery slots and the spacing between batteries. Other parameters include LidThickness and LidPlay to adjust the thickness of lid top and sides, and for proper fit on the battery box. The lid and box have spherical snaps to hold the lid in place, and on my Prusa printing at 0.3mm layers and a 1mm lid thickness with play of 0.3mm it was a fairly tight fit at first, but just right after a few times.
The settings I've used are:
By default, the box and lid render together. If the configuration is small enough to fit on your printer bed, you can export one STL file and just print them together. Otherwise, in the parameters you can uncheck PrintLid or PrintBox, then render and export each component's file separately.
I have included the STL and Gcode files for a box holding 24 AAs and 20 AAAs so you can see the time and material required for a fairly large box. I also printed a small battery box and lid as a test, 4 AAA batteries in a 2x2 configuration, shown in the photos. This printed in 2 hours and 3 minutes.
Note the Gcode file for the lid has special settings to print as transparent as possible with clear PLA:
Now I can see how many batteries I have without taking off the lid!
With the OpenSCAD file you can remix as you wish.
The author marked this model as their own original creation.