nuxx-net-xnrgb7.txt (10876B)
1 [1]Press "Enter" to skip to content 2 [2]nuxx.net 3 4 Making, baking, and (un-)breaking things in Southeast Michigan. 5 6 open menu mobile menu toggle button 7 8 • [4] facebook 9 • [5] [email protected] 10 11 Search [7][ ] 12 • [8]About 13 • [9]Wiki (Archive) 14 15 OpenSCAD Is Kinda Neat 16 17 Published [10]December 20, 2025 18 [11][Screenshot-2025-12-20-at-12]Designing a simple battery holder in OpenSCAD. 19 20 Earlier this year I designed a very basic box/organizer for [12]AA and [13]AAA 21 batteries in [14]Autodesk Fusion, making it parameterized so that by changing a 22 few variables one could adjust the battery type/size, rows/columns, etc. This 23 worked well, and after [15]uploading it to Printables earlier today I realized 24 that reimplementing it would probably be a good way to learn the basics of [16] 25 OpenSCAD. 26 27 OpenSCAD is a rather different type of CAD tool, one in which you write code to 28 generate objects. Because my battery holder is very simple (just a box with a 29 pattern of cutouts) and uses input parameters, I figured it’d be a good intro 30 to a new language / tool. And in the future might even be better than firing up 31 Fusion for such simple designs. 32 33 After going through part of [17]the tutorial and an hour or so of poking, 34 here’s the result: [18]battery_holder_generator.scad 35 36 [19][Screenshot-2025-12-20-at-12]Slicer showing the Fusion model on top and 37 OpenSCAD on bottom. 38 39 By changing just a few variables — numRows and numColumns and batteryType — one 40 can render a customized battery holder which can then be plopped into a [20] 41 slicer and printed. No heavy/expensive CAD software needed and the output is 42 effectively the same. 43 44 Without comments or informative output, this is the meat of the code: 45 46 AA = 15; 47 AAA = 11; 48 heightCompartment = 19; 49 thicknessWall = 1; 50 numRows = 4; 51 numColumns = 10; 52 batteryType = AA; 53 54 widthBox = (numRows * batteryType) + ((numRows + 1) * thicknessWall); 55 lengthBox = (numColumns * batteryType) + ((numColumns + 1) * thicknessWall); 56 depthBox = heightCompartment + thicknessWall; 57 58 difference() { 59 cube([lengthBox, widthBox, depthBox]); 60 for (c = [ 1 : numColumns ]) 61 for (r = [ 1 : numRows ]) 62 let ( 63 startColumn = ((c * thicknessWall) + ((c - 1) * batteryType)), 64 startRow = ((r * thicknessWall) + ((r - 1) * batteryType)) 65 ) 66 { 67 translate([startColumn, startRow, thicknessWall]) 68 cube([batteryType, batteryType, heightCompartment + 1]); 69 } 70 }; 71 72 Simply, it draws a box and cuts out the holes. (The first cube() draws the main 73 box, then difference() subtracts the battery holes via the second cube() as 74 their quantity and location (via translate()) is iterated. 75 76 That’s it. Pretty neat, eh? 77 78 (One part that confused me is how I needed to use [21]let() to define 79 startColumn and startRow inside the loop. I don’t understand this…) 80 81 While this probably won’t be very helpful for more complicated designs, I can 82 see this being super useful for bearing drifts, spacers, and other similar 83 simple (yet incredibly useful in real life) geometric shapes. 84 85 Published in [22]computers and [23]making things 86 87 Previous Post [24]Solar Radiation (Sun) Shield for Temperature Sensors 88 Next Post [25]Home Assistant as Personal Device Tracker 89 90 Sidebar 91 92 Recent Posts 93 94 • [26]Home Assistant as Personal Device Tracker December 26, 2025 95 • [27]OpenSCAD Is Kinda Neat December 20, 2025 96 • [28]Solar Radiation (Sun) Shield for Temperature Sensors December 19, 2025 97 • [29]Riser Feet for Wahoo KICKR CORE 2 December 6, 2025 98 • [30]Wireshark 4.6.0 Supports macOS pktap Metadata (PID, Process Name, etc.) 99 October 14, 2025 100 • [31]Fat Bike Peanuts (Presta Nuts for Single Wall Fatbike Rims) June 21, 101 2025 102 • [32]Windows 10/11 Drivers for Epson Perfection 3170 Photo Scanner April 2, 103 2025 104 • [33]The History of Fibber Mountain March 21, 2025 105 • [34]Fox 803-01-727 Replaces 803-01-993 March 20, 2025 106 • [35]Automated Private Mobile Phone Photo Backup (Android to Apple Photos) 107 January 23, 2025 108 • [36]ZOOZ ZSE44 Flat Lines at 0° (C or F) January 22, 2025 109 • [37]Bambu Lab P1S on IoT VLAN December 19, 2024 110 • [38]Fix for Leaky Valves on Single Wall Fatbike Rims December 6, 2024 111 • [39]Ride Dirt Trails, Not Mud Trails: Reposted November 22, 2024 112 • [40]HDMI-CEC to Onkyo RI Bridge September 2, 2024 113 • [41]Onkyo RI for ESPHome / Home Assistant August 19, 2024 114 • [42]New XC Bike: Pivot Mach 4 SL v3 May 12, 2024 115 • [43]Fork-Mount Bike Rack for Honda Odyssey (2018+) March 5, 2024 116 • [44]Sunrise-like Alarm Clock via Home Assistant + Android January 19, 2024 117 • [45]_wahoo-fitness-tnp._tcp.local January 10, 2024 118 119 Categories 120 121 • [46]acquired things 122 • [47]around the house 123 • [48]automotive 124 • [49]beer 125 • [50]computers 126 • [51]cycling 127 • [52]electronics 128 • [53]family 129 • [54]finances 130 • [55]food 131 • [56]found things 132 • [57]games 133 • [58]health 134 • [59]livejournal 135 • [60]making things 136 • [61]mapping 137 • [62]moved from livejournal 138 • [63]movies 139 • [64]music 140 • [65]nuxx.net 141 • [66]outdoors 142 • [67]politics 143 • [68]travel 144 • [69]weather 145 • [70]work 146 147 Posts 148 149 • [71]Home Assistant as Personal Device Tracker 150 • [72]OpenSCAD Is Kinda Neat 151 • [73]Solar Radiation (Sun) Shield for Temperature Sensors 152 • [74]Riser Feet for Wahoo KICKR CORE 2 153 • [75]Wireshark 4.6.0 Supports macOS pktap Metadata (PID, Process Name, etc.) 154 • [76]Fat Bike Peanuts (Presta Nuts for Single Wall Fatbike Rims) 155 • [77]Windows 10/11 Drivers for Epson Perfection 3170 Photo Scanner 156 • [78]The History of Fibber Mountain 157 • [79]Fox 803-01-727 Replaces 803-01-993 158 • [80]Automated Private Mobile Phone Photo Backup (Android to Apple Photos) 159 160 [81]Period WordPress Theme by Compete Themes. 161 Scroll to the top 162 163 References: 164 165 [1] https://nuxx.net/blog/2025/12/20/openscad-is-kinda-neat/#main 166 [2] https://nuxx.net/blog 167 [4] https://www.facebook.com/steve.vigneau 168 [5] mailto:[email protected] 169 [8] https://nuxx.net/blog/about/ 170 [9] https://nuxx.net/wiki_archive/A/Main_Page 171 [10] https://nuxx.net/blog/2025/12/ 172 [11] https://nuxx.net/blog/wp-content/uploads/2025/12/Screenshot-2025-12-20-at-12.11.35-PM-scaled.png 173 [12] https://en.wikipedia.org/wiki/AA_battery 174 [13] https://en.wikipedia.org/wiki/AAA_battery 175 [14] https://www.autodesk.com/products/fusion-360/ 176 [15] https://www.printables.com/model/1522509-simple-battery-holder-aa-and-aaa-w-parameterized-f 177 [16] https://openscad.org/ 178 [17] https://en.wikibooks.org/wiki/OpenSCAD_Tutorial 179 [18] https://nuxx.net/files/3d_printing/battery_holder_generator.scad 180 [19] https://nuxx.net/blog/wp-content/uploads/2025/12/Screenshot-2025-12-20-at-12.30.03-PM-scaled.png 181 [20] https://en.wikipedia.org/wiki/Slicer_(3D_printing) 182 [21] https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions#let 183 [22] https://nuxx.net/blog/category/computers/ 184 [23] https://nuxx.net/blog/category/making-things/ 185 [24] https://nuxx.net/blog/2025/12/19/solar-radiation-sun-shield-for-temperature-sensors/ 186 [25] https://nuxx.net/blog/2025/12/26/home-assistant-as-personal-device-tracker/ 187 [26] https://nuxx.net/blog/2025/12/26/home-assistant-as-personal-device-tracker/ 188 [27] https://nuxx.net/blog/2025/12/20/openscad-is-kinda-neat/ 189 [28] https://nuxx.net/blog/2025/12/19/solar-radiation-sun-shield-for-temperature-sensors/ 190 [29] https://nuxx.net/blog/2025/12/06/riser-feet-for-wahoo-kickr-core-2/ 191 [30] https://nuxx.net/blog/2025/10/14/wireshark-4-6-0-supports-macos-pktap-metadata-pid-process-name-etc/ 192 [31] https://nuxx.net/blog/2025/06/21/fat-bike-peanuts-presta-nuts-for-single-wall-fatbike-rims/ 193 [32] https://nuxx.net/blog/2025/04/02/windows-10-11-drivers-for-epson-perfection-3170-photo-scanner/ 194 [33] https://nuxx.net/blog/2025/03/21/the-history-of-fibber-mountain/ 195 [34] https://nuxx.net/blog/2025/03/20/fox-803-01-727-replaces-803-01-993/ 196 [35] https://nuxx.net/blog/2025/01/23/automated-private-mobile-phone-photo-backup-android-to-apple-photos/ 197 [36] https://nuxx.net/blog/2025/01/22/zooz-zse44-flat-lines-at-0-c-or-f/ 198 [37] https://nuxx.net/blog/2024/12/19/bambu-lab-p1s-on-iot-vlan/ 199 [38] https://nuxx.net/blog/2024/12/06/fix-for-leaky-valves-on-single-wall-fatbike-rims/ 200 [39] https://nuxx.net/blog/2024/11/22/ride-dirt-trails-not-mud-trails-reposted/ 201 [40] https://nuxx.net/blog/2024/09/02/hdmi-cec-to-onkyo-ri-bridge/ 202 [41] https://nuxx.net/blog/2024/08/19/onkyo-ri-for-esphome-home-assistant/ 203 [42] https://nuxx.net/blog/2024/05/12/new-xc-bike-pivot-mach-4-sl-v3/ 204 [43] https://nuxx.net/blog/2024/03/05/fork-mount-bike-rack-for-honda-odyssey-2018/ 205 [44] https://nuxx.net/blog/2024/01/19/sunrise-like-alarm-clock-via-home-assistant-android/ 206 [45] https://nuxx.net/blog/2024/01/10/_wahoo-fitness-tnp-_tcp-local/ 207 [46] https://nuxx.net/blog/category/acquired-things/ 208 [47] https://nuxx.net/blog/category/around-the-house/ 209 [48] https://nuxx.net/blog/category/automotive/ 210 [49] https://nuxx.net/blog/category/beer/ 211 [50] https://nuxx.net/blog/category/computers/ 212 [51] https://nuxx.net/blog/category/cycling/ 213 [52] https://nuxx.net/blog/category/electronics/ 214 [53] https://nuxx.net/blog/category/family/ 215 [54] https://nuxx.net/blog/category/finances/ 216 [55] https://nuxx.net/blog/category/food/ 217 [56] https://nuxx.net/blog/category/found-things/ 218 [57] https://nuxx.net/blog/category/games/ 219 [58] https://nuxx.net/blog/category/health/ 220 [59] https://nuxx.net/blog/category/livejournal/ 221 [60] https://nuxx.net/blog/category/making-things/ 222 [61] https://nuxx.net/blog/category/mapping/ 223 [62] https://nuxx.net/blog/category/moved-from-livejournal/ 224 [63] https://nuxx.net/blog/category/movies/ 225 [64] https://nuxx.net/blog/category/music/ 226 [65] https://nuxx.net/blog/category/nuxxnet/ 227 [66] https://nuxx.net/blog/category/outdoors/ 228 [67] https://nuxx.net/blog/category/politics/ 229 [68] https://nuxx.net/blog/category/travel/ 230 [69] https://nuxx.net/blog/category/weather/ 231 [70] https://nuxx.net/blog/category/work/ 232 [71] https://nuxx.net/blog/2025/12/26/home-assistant-as-personal-device-tracker/ 233 [72] https://nuxx.net/blog/2025/12/20/openscad-is-kinda-neat/ 234 [73] https://nuxx.net/blog/2025/12/19/solar-radiation-sun-shield-for-temperature-sensors/ 235 [74] https://nuxx.net/blog/2025/12/06/riser-feet-for-wahoo-kickr-core-2/ 236 [75] https://nuxx.net/blog/2025/10/14/wireshark-4-6-0-supports-macos-pktap-metadata-pid-process-name-etc/ 237 [76] https://nuxx.net/blog/2025/06/21/fat-bike-peanuts-presta-nuts-for-single-wall-fatbike-rims/ 238 [77] https://nuxx.net/blog/2025/04/02/windows-10-11-drivers-for-epson-perfection-3170-photo-scanner/ 239 [78] https://nuxx.net/blog/2025/03/21/the-history-of-fibber-mountain/ 240 [79] https://nuxx.net/blog/2025/03/20/fox-803-01-727-replaces-803-01-993/ 241 [80] https://nuxx.net/blog/2025/01/23/automated-private-mobile-phone-photo-backup-android-to-apple-photos/ 242 [81] https://www.competethemes.com/period/