I need Battery compartments for many of my electronics projects and buy them usually in various sizes, but since i have a makerbot I am thinking about how to print them myself. So I just wrote a openscad-script that generates battery compartments. It handles various battery types from AAA to D and can generate compartments for even and odd battery numbers.
Download the OpenSCAD file enter the type and number of batteries you need and generate a stl file. Then either add it to your model or use it as a standalone compartment. The only thing you need to add (besides batteries) are litte metall stripes for the contacts.