├── COPYING.CC-BY-NC-SA.txt ├── COPYING.MIT.txt ├── README.md ├── baseplate_magnet_jig.py ├── block_test.py ├── examples ├── covers.py ├── ender_3_allen_keys.py ├── etc_foot_holder.py ├── game_carts │ ├── ds.py │ ├── gb.py │ ├── illustration.py │ └── switch.py ├── rulers.py ├── sewing_feet_holder.py ├── tube_holders.py └── walking_foot_holder.py └── gridfinity.py /COPYING.CC-BY-NC-SA.txt: -------------------------------------------------------------------------------- 1 | Attribution-NonCommercial-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International 58 | Public License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-NonCommercial-ShareAlike 4.0 International Public License 63 | ("Public License"). To the extent this Public License may be 64 | interpreted as a contract, You are granted the Licensed Rights in 65 | consideration of Your acceptance of these terms and conditions, and the 66 | Licensor grants You such rights in consideration of benefits the 67 | Licensor receives from making the Licensed Material available under 68 | these terms and conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Adapter's License means the license You apply to Your Copyright 84 | and Similar Rights in Your contributions to Adapted Material in 85 | accordance with the terms and conditions of this Public License. 86 | 87 | c. BY-NC-SA Compatible License means a license listed at 88 | creativecommons.org/compatiblelicenses, approved by Creative 89 | Commons as essentially the equivalent of this Public License. 90 | 91 | d. Copyright and Similar Rights means copyright and/or similar rights 92 | closely related to copyright including, without limitation, 93 | performance, broadcast, sound recording, and Sui Generis Database 94 | Rights, without regard to how the rights are labeled or 95 | categorized. For purposes of this Public License, the rights 96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 97 | Rights. 98 | 99 | e. Effective Technological Measures means those measures that, in the 100 | absence of proper authority, may not be circumvented under laws 101 | fulfilling obligations under Article 11 of the WIPO Copyright 102 | Treaty adopted on December 20, 1996, and/or similar international 103 | agreements. 104 | 105 | f. Exceptions and Limitations means fair use, fair dealing, and/or 106 | any other exception or limitation to Copyright and Similar Rights 107 | that applies to Your use of the Licensed Material. 108 | 109 | g. License Elements means the license attributes listed in the name 110 | of a Creative Commons Public License. The License Elements of this 111 | Public License are Attribution, NonCommercial, and ShareAlike. 112 | 113 | h. Licensed Material means the artistic or literary work, database, 114 | or other material to which the Licensor applied this Public 115 | License. 116 | 117 | i. Licensed Rights means the rights granted to You subject to the 118 | terms and conditions of this Public License, which are limited to 119 | all Copyright and Similar Rights that apply to Your use of the 120 | Licensed Material and that the Licensor has authority to license. 121 | 122 | j. Licensor means the individual(s) or entity(ies) granting rights 123 | under this Public License. 124 | 125 | k. NonCommercial means not primarily intended for or directed towards 126 | commercial advantage or monetary compensation. For purposes of 127 | this Public License, the exchange of the Licensed Material for 128 | other material subject to Copyright and Similar Rights by digital 129 | file-sharing or similar means is NonCommercial provided there is 130 | no payment of monetary compensation in connection with the 131 | exchange. 132 | 133 | l. Share means to provide material to the public by any means or 134 | process that requires permission under the Licensed Rights, such 135 | as reproduction, public display, public performance, distribution, 136 | dissemination, communication, or importation, and to make material 137 | available to the public including in ways that members of the 138 | public may access the material from a place and at a time 139 | individually chosen by them. 140 | 141 | m. Sui Generis Database Rights means rights other than copyright 142 | resulting from Directive 96/9/EC of the European Parliament and of 143 | the Council of 11 March 1996 on the legal protection of databases, 144 | as amended and/or succeeded, as well as other essentially 145 | equivalent rights anywhere in the world. 146 | 147 | n. You means the individual or entity exercising the Licensed Rights 148 | under this Public License. Your has a corresponding meaning. 149 | 150 | 151 | Section 2 -- Scope. 152 | 153 | a. License grant. 154 | 155 | 1. Subject to the terms and conditions of this Public License, 156 | the Licensor hereby grants You a worldwide, royalty-free, 157 | non-sublicensable, non-exclusive, irrevocable license to 158 | exercise the Licensed Rights in the Licensed Material to: 159 | 160 | a. reproduce and Share the Licensed Material, in whole or 161 | in part, for NonCommercial purposes only; and 162 | 163 | b. produce, reproduce, and Share Adapted Material for 164 | NonCommercial purposes only. 165 | 166 | 2. Exceptions and Limitations. For the avoidance of doubt, where 167 | Exceptions and Limitations apply to Your use, this Public 168 | License does not apply, and You do not need to comply with 169 | its terms and conditions. 170 | 171 | 3. Term. The term of this Public License is specified in Section 172 | 6(a). 173 | 174 | 4. Media and formats; technical modifications allowed. The 175 | Licensor authorizes You to exercise the Licensed Rights in 176 | all media and formats whether now known or hereafter created, 177 | and to make technical modifications necessary to do so. The 178 | Licensor waives and/or agrees not to assert any right or 179 | authority to forbid You from making technical modifications 180 | necessary to exercise the Licensed Rights, including 181 | technical modifications necessary to circumvent Effective 182 | Technological Measures. For purposes of this Public License, 183 | simply making modifications authorized by this Section 2(a) 184 | (4) never produces Adapted Material. 185 | 186 | 5. Downstream recipients. 187 | 188 | a. Offer from the Licensor -- Licensed Material. Every 189 | recipient of the Licensed Material automatically 190 | receives an offer from the Licensor to exercise the 191 | Licensed Rights under the terms and conditions of this 192 | Public License. 193 | 194 | b. Additional offer from the Licensor -- Adapted Material. 195 | Every recipient of Adapted Material from You 196 | automatically receives an offer from the Licensor to 197 | exercise the Licensed Rights in the Adapted Material 198 | under the conditions of the Adapter's License You apply. 199 | 200 | c. No downstream restrictions. You may not offer or impose 201 | any additional or different terms or conditions on, or 202 | apply any Effective Technological Measures to, the 203 | Licensed Material if doing so restricts exercise of the 204 | Licensed Rights by any recipient of the Licensed 205 | Material. 206 | 207 | 6. No endorsement. Nothing in this Public License constitutes or 208 | may be construed as permission to assert or imply that You 209 | are, or that Your use of the Licensed Material is, connected 210 | with, or sponsored, endorsed, or granted official status by, 211 | the Licensor or others designated to receive attribution as 212 | provided in Section 3(a)(1)(A)(i). 213 | 214 | b. Other rights. 215 | 216 | 1. Moral rights, such as the right of integrity, are not 217 | licensed under this Public License, nor are publicity, 218 | privacy, and/or other similar personality rights; however, to 219 | the extent possible, the Licensor waives and/or agrees not to 220 | assert any such rights held by the Licensor to the limited 221 | extent necessary to allow You to exercise the Licensed 222 | Rights, but not otherwise. 223 | 224 | 2. Patent and trademark rights are not licensed under this 225 | Public License. 226 | 227 | 3. To the extent possible, the Licensor waives any right to 228 | collect royalties from You for the exercise of the Licensed 229 | Rights, whether directly or through a collecting society 230 | under any voluntary or waivable statutory or compulsory 231 | licensing scheme. In all other cases the Licensor expressly 232 | reserves any right to collect such royalties, including when 233 | the Licensed Material is used other than for NonCommercial 234 | purposes. 235 | 236 | 237 | Section 3 -- License Conditions. 238 | 239 | Your exercise of the Licensed Rights is expressly made subject to the 240 | following conditions. 241 | 242 | a. Attribution. 243 | 244 | 1. If You Share the Licensed Material (including in modified 245 | form), You must: 246 | 247 | a. retain the following if it is supplied by the Licensor 248 | with the Licensed Material: 249 | 250 | i. identification of the creator(s) of the Licensed 251 | Material and any others designated to receive 252 | attribution, in any reasonable manner requested by 253 | the Licensor (including by pseudonym if 254 | designated); 255 | 256 | ii. a copyright notice; 257 | 258 | iii. a notice that refers to this Public License; 259 | 260 | iv. a notice that refers to the disclaimer of 261 | warranties; 262 | 263 | v. a URI or hyperlink to the Licensed Material to the 264 | extent reasonably practicable; 265 | 266 | b. indicate if You modified the Licensed Material and 267 | retain an indication of any previous modifications; and 268 | 269 | c. indicate the Licensed Material is licensed under this 270 | Public License, and include the text of, or the URI or 271 | hyperlink to, this Public License. 272 | 273 | 2. You may satisfy the conditions in Section 3(a)(1) in any 274 | reasonable manner based on the medium, means, and context in 275 | which You Share the Licensed Material. For example, it may be 276 | reasonable to satisfy the conditions by providing a URI or 277 | hyperlink to a resource that includes the required 278 | information. 279 | 3. If requested by the Licensor, You must remove any of the 280 | information required by Section 3(a)(1)(A) to the extent 281 | reasonably practicable. 282 | 283 | b. ShareAlike. 284 | 285 | In addition to the conditions in Section 3(a), if You Share 286 | Adapted Material You produce, the following conditions also apply. 287 | 288 | 1. The Adapter's License You apply must be a Creative Commons 289 | license with the same License Elements, this version or 290 | later, or a BY-NC-SA Compatible License. 291 | 292 | 2. You must include the text of, or the URI or hyperlink to, the 293 | Adapter's License You apply. You may satisfy this condition 294 | in any reasonable manner based on the medium, means, and 295 | context in which You Share Adapted Material. 296 | 297 | 3. You may not offer or impose any additional or different terms 298 | or conditions on, or apply any Effective Technological 299 | Measures to, Adapted Material that restrict exercise of the 300 | rights granted under the Adapter's License You apply. 301 | 302 | 303 | Section 4 -- Sui Generis Database Rights. 304 | 305 | Where the Licensed Rights include Sui Generis Database Rights that 306 | apply to Your use of the Licensed Material: 307 | 308 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 309 | to extract, reuse, reproduce, and Share all or a substantial 310 | portion of the contents of the database for NonCommercial purposes 311 | only; 312 | 313 | b. if You include all or a substantial portion of the database 314 | contents in a database in which You have Sui Generis Database 315 | Rights, then the database in which You have Sui Generis Database 316 | Rights (but not its individual contents) is Adapted Material, 317 | including for purposes of Section 3(b); and 318 | 319 | c. You must comply with the conditions in Section 3(a) if You Share 320 | all or a substantial portion of the contents of the database. 321 | 322 | For the avoidance of doubt, this Section 4 supplements and does not 323 | replace Your obligations under this Public License where the Licensed 324 | Rights include other Copyright and Similar Rights. 325 | 326 | 327 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 328 | 329 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 330 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 331 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 332 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 333 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 334 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 335 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 336 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 337 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 338 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 339 | 340 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 341 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 342 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 343 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 344 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 345 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 346 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 347 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 348 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 349 | 350 | c. The disclaimer of warranties and limitation of liability provided 351 | above shall be interpreted in a manner that, to the extent 352 | possible, most closely approximates an absolute disclaimer and 353 | waiver of all liability. 354 | 355 | 356 | Section 6 -- Term and Termination. 357 | 358 | a. This Public License applies for the term of the Copyright and 359 | Similar Rights licensed here. However, if You fail to comply with 360 | this Public License, then Your rights under this Public License 361 | terminate automatically. 362 | 363 | b. Where Your right to use the Licensed Material has terminated under 364 | Section 6(a), it reinstates: 365 | 366 | 1. automatically as of the date the violation is cured, provided 367 | it is cured within 30 days of Your discovery of the 368 | violation; or 369 | 370 | 2. upon express reinstatement by the Licensor. 371 | 372 | For the avoidance of doubt, this Section 6(b) does not affect any 373 | right the Licensor may have to seek remedies for Your violations 374 | of this Public License. 375 | 376 | c. For the avoidance of doubt, the Licensor may also offer the 377 | Licensed Material under separate terms or conditions or stop 378 | distributing the Licensed Material at any time; however, doing so 379 | will not terminate this Public License. 380 | 381 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 382 | License. 383 | 384 | 385 | Section 7 -- Other Terms and Conditions. 386 | 387 | a. The Licensor shall not be bound by any additional or different 388 | terms or conditions communicated by You unless expressly agreed. 389 | 390 | b. Any arrangements, understandings, or agreements regarding the 391 | Licensed Material not stated herein are separate from and 392 | independent of the terms and conditions of this Public License. 393 | 394 | 395 | Section 8 -- Interpretation. 396 | 397 | a. For the avoidance of doubt, this Public License does not, and 398 | shall not be interpreted to, reduce, limit, restrict, or impose 399 | conditions on any use of the Licensed Material that could lawfully 400 | be made without permission under this Public License. 401 | 402 | b. To the extent possible, if any provision of this Public License is 403 | deemed unenforceable, it shall be automatically reformed to the 404 | minimum extent necessary to make it enforceable. If the provision 405 | cannot be reformed, it shall be severed from this Public License 406 | without affecting the enforceability of the remaining terms and 407 | conditions. 408 | 409 | c. No term or condition of this Public License will be waived and no 410 | failure to comply consented to unless expressly agreed to by the 411 | Licensor. 412 | 413 | d. Nothing in this Public License constitutes or may be interpreted 414 | as a limitation upon, or waiver of, any privileges and immunities 415 | that apply to the Licensor or You, including from the legal 416 | processes of any jurisdiction or authority. 417 | 418 | ======================================================================= 419 | 420 | Creative Commons is not a party to its public 421 | licenses. Notwithstanding, Creative Commons may elect to apply one of 422 | its public licenses to material it publishes and in those instances 423 | will be considered the “Licensor.” The text of the Creative Commons 424 | public licenses is dedicated to the public domain under the CC0 Public 425 | Domain Dedication. Except for the limited purpose of indicating that 426 | material is shared under a Creative Commons public license or as 427 | otherwise permitted by the Creative Commons policies published at 428 | creativecommons.org/policies, Creative Commons does not authorize the 429 | use of the trademark "Creative Commons" or any other trademark or logo 430 | of Creative Commons without its prior written consent including, 431 | without limitation, in connection with any unauthorized modifications 432 | to any of its public licenses or any other arrangements, 433 | understandings, or agreements concerning use of licensed material. For 434 | the avoidance of doubt, this paragraph does not form part of the 435 | public licenses. 436 | 437 | Creative Commons may be contacted at creativecommons.org. 438 | 439 | -------------------------------------------------------------------------------- /COPYING.MIT.txt: -------------------------------------------------------------------------------- 1 | Copyright ©2022-2024 kmeisthax. 2 | 3 | Copyright ©2022-2024 Zach Freedman. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the “Software”), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gridfinity for CADQuery 2 | 3 | This is a port of Zach Freedman's [Gridfinity](https://www.youtube.com/watch?v=ra_9zU-mnl8&t=1067s) 4 | storage system to [CADQuery](https://github.com/CadQuery/cadquery). 5 | 6 | ## Usage 7 | 8 | See the `block_test.py` for now. 9 | 10 | ## Licensing 11 | 12 | Gridfinity is ©2022-2023 Zach Freedman. 13 | 14 | Zach [actually decided to relicense](https://youtu.be/ofI2OCq_QqA?t=343), so 15 | this project and the example models are now available under the 16 | [MIT license](https://opensource.org/license/mit/). 17 | 18 | For models released before April 2nd of 2023, you may continue using the silly 19 | [CC BY-NC-SA 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/) 20 | license terms, because they are irrevocable. But *why would you*!? -------------------------------------------------------------------------------- /baseplate_magnet_jig.py: -------------------------------------------------------------------------------- 1 | import cadquery as cq 2 | import gridfinity 3 | 4 | jig_separator_pin_radius = 13 5 | 6 | jig_handle = cq.Workplane("XY")\ 7 | .rect(12, 1.5)\ 8 | .extrude(2)\ 9 | .faces(">Z")\ 10 | .rect(12, 4)\ 11 | .extrude(1) 12 | 13 | jig_carrier = cq.Workplane("XY")\ 14 | .placeSketch(gridfinity.inset_profile(1, 1, gridfinity.block_spacing / 2))\ 15 | .extrude(gridfinity.magnet_depth + 0.5)\ 16 | .faces("Z")\ 19 | .rect(gridfinity.grid_unit - gridfinity.magnet_inset * 2, gridfinity.grid_unit - gridfinity.magnet_inset * 2, forConstruction=True)\ 20 | .vertices()\ 21 | .hole(gridfinity.magnet_diameter, gridfinity.magnet_depth)\ 22 | .faces(">Z")\ 23 | .hole(20, gridfinity.magnet_depth + 0.5)\ 24 | .union(jig_handle.val().moved(cq.Location(cq.Vector([0, 13, gridfinity.magnet_depth + 0.5]))))\ 25 | .union(jig_handle.val().moved(cq.Location(cq.Vector([0, -13, gridfinity.magnet_depth + 0.5]))))\ 26 | .faces(">Z")\ 27 | .polarArray(jig_separator_pin_radius, 0, 360, 4)\ 28 | .cutEach(lambda c: cq.Solid.makeCylinder(2.25, 2.5, cq.Vector(), cq.Vector(0, 0, 1)).moved(c), True, clean=True) 29 | 30 | jig_separator = cq.Workplane("XY")\ 31 | .placeSketch(gridfinity.inset_profile(1, 1, gridfinity.block_mating_inset))\ 32 | .extrude(-1.25)\ 33 | .faces(">Z")\ 34 | .polarArray(jig_separator_pin_radius, 0, 360, 4)\ 35 | .eachpoint(lambda c: cq.Solid.makeCylinder(1, 1.75, cq.Vector(), cq.Vector(0, 0, 1)).moved(c), combine="a", clean=True)\ 36 | .faces(">Z")\ 37 | .cylinder(1, 1.5, cq.Vector(0,0,1))\ 38 | .faces("Y")\ 37 | .workplane()\ 38 | .transformed((0,0,0), (0, -extra_depth, 0))\ 39 | .rect(gridfinity.grid_unit * w, gridfinity.block_extrusion(1) + extra_depth, centered = [True, False])\ 40 | .cutBlind(-100 * w)\ 41 | .faces(">Z")\ 42 | .workplane(centerOption='CenterOfBoundBox')\ 43 | .transformed((0,0,0), (0, -gridfinity.top_surface_length(h) / 2 - 20, 0))\ 44 | .rect(gridfinity.grid_unit * w, label_lip_height + 20, centered = [True, False])\ 45 | .cutBlind(-100 * w)\ 46 | .faces("Z")\ 51 | .fillet(0.25) 52 | 53 | def topplate(w, h): 54 | """Generate a top cover for a set of height-leveled Gridfinity blocks. 55 | 56 | This is basically the inverse of a baseplate.""" 57 | 58 | with_cutouts = cq.Workplane("XY")\ 59 | .gridfinity_block(w, h, 0.5)\ 60 | .gridfinity_block_lip(w, h, holes=False)\ 61 | .faces(">Z")\ 62 | .edges(cq.NearestToPointSelector([(w * gridfinity.grid_unit / 2), (h * gridfinity.grid_unit / 2), gridfinity.block_extrusion(1)]))\ 63 | .fillet(gridfinity.block_stacking_lip / 2) 64 | 65 | return with_cutouts 66 | 67 | def midplate(w, h): 68 | """Generate a vertical divider, which is essentially a thin baseplate that 69 | can be stacked on top of other storage blocks. 70 | 71 | The purpose of vertical dividers are to prevent blocks with magnets from 72 | magnetizing parts in divider bins stacked below them. They're sort of like 73 | weighted baseplates, except they are sized to stack as if they were 1x tall 74 | blocks.""" 75 | 76 | with_cutouts = cq.Workplane("XY")\ 77 | .gridfinity_block(w, h, 1)\ 78 | .gridfinity_block_lip(w, h, holes=False)\ 79 | .faces(">Z")\ 80 | .rarray(gridfinity.grid_unit, gridfinity.grid_unit, w, h)\ 81 | .eachpoint(lambda c: cq.Workplane("XY")\ 82 | .placeSketch(gridfinity.inset_profile(1, 1, gridfinity.block_mating_inset))\ 83 | .extrude(gridfinity.stacking_mating_depth * -1)\ 84 | .val()\ 85 | .moved(c)\ 86 | .moved(cq.Location(cq.Vector(0, 0, gridfinity.block_extrusion(1)))), 87 | combine="cut", 88 | clean=True) 89 | 90 | filleted = with_cutouts 91 | 92 | for i in range(0, w): 93 | for j in range(0, h): 94 | x = (i * gridfinity.grid_unit) - (w * gridfinity.grid_unit / 2) + gridfinity.block_mating_inset 95 | y = (j * gridfinity.grid_unit) - (h * gridfinity.grid_unit / 2) + gridfinity.block_mating_inset 96 | z = gridfinity.block_extrusion(1) 97 | 98 | try: 99 | filleted = filleted\ 100 | .edges(cq.NearestToPointSelector([x + gridfinity.grid_unit / 2, y + gridfinity.grid_unit / 2, z]))\ 101 | .chamfer(gridfinity.block_mating_inset - gridfinity.block_spacing * 0.5 - gridfinity.block_stacking_lip)\ 102 | .edges(cq.NearestToPointSelector([x + gridfinity.grid_unit / 2, y + gridfinity.grid_unit / 2, z - gridfinity.block_mating_depth]))\ 103 | .chamfer(gridfinity.block_stacking_chamfer)\ 104 | .faces(">Z")\ 105 | .edges(cq.NearestToPointSelector([x, y, z]))\ 106 | .fillet(gridfinity.block_stacking_lip / 2) 107 | except: 108 | continue 109 | 110 | return filleted\ 111 | .faces(">Z")\ 112 | .edges(cq.NearestToPointSelector([(w * gridfinity.grid_unit / 2), (h * gridfinity.grid_unit / 2), gridfinity.block_extrusion(1)]))\ 113 | .fillet(gridfinity.block_stacking_lip / 2) 114 | 115 | for i in range(1,7): 116 | for j in range(1,7): 117 | if j > i: 118 | continue 119 | 120 | x = (i * (i + 1) / 2) * gridfinity.grid_unit 121 | y = (j * (j + 1) / 2) * gridfinity.grid_unit 122 | 123 | if j == 1 and i <= 5: 124 | locals()["cover" + str(i) + "_" + str(j)] = cover(i, j).translate((x, y, -10)) 125 | 126 | locals()["midplate" + str(i) + "_" + str(j)] = midplate(i, j).translate((x, y, 0)) 127 | locals()["topplate" + str(i) + "_" + str(j)] = topplate(i, j).translate((x, y, 20)) -------------------------------------------------------------------------------- /examples/ender_3_allen_keys.py: -------------------------------------------------------------------------------- 1 | import cadquery as cq 2 | import gridfinity 3 | from math import pow, e, cos, pi, sin, floor 4 | 5 | tolerance = 0.25 6 | 7 | # Radius of the fillets on the allen key holes. 8 | # NOTE: If you get command not done errors, those almost always are the result 9 | # of a chamfer or fillet operation failing because the geometry makes no sense 10 | # to CADQuery. There's actually three ways I've seen fillets fail: 11 | # 12 | # 1. The fillet radius is high enough to join two holes together 13 | # 2. The logistic spiral code is putting holes on top of one another 14 | # 3. The allen key holes are so far from the center they are cutting into the 15 | # Gridfinity stacking lip, which confuses everything 16 | # 17 | # When in doubt set this to the lowest nonzero value you can make it handle 18 | # or delete all the fillet calls that use this. 19 | fillet_radius = 0.75 20 | 21 | def allen_key_profile(across_flat_dia): 22 | """Generate the profile of an allen key wrench with a given across-flats 23 | diameter.""" 24 | 25 | return cq.Workplane("XY")\ 26 | .polygon(6, across_flat_dia / cos(360 / 6 / 2 * pi / 180) + tolerance)\ 27 | .extrude(100)\ 28 | .val() 29 | 30 | def optimal_point_distance(physical_widths): 31 | """Calculate the optimal distance between points on a polygon with as many 32 | points/sides as there are allen keys to accomodate.""" 33 | return physical_widths[0] + 5.5 * len(physical_widths) 34 | 35 | def allen_key_cutout_generator(points, depth, distance): 36 | """Create an allen key cutout generator function for use with cuteach. 37 | 38 | Each generator should only be used once as there is internal closure state 39 | that may not reset properly if reused.""" 40 | i = 0 41 | 42 | def inner(p): 43 | nonlocal i 44 | 45 | key_dia = points[i % len(points)] 46 | 47 | old_p = list(p.toTuple()[0]) 48 | phi = ((i % len(points))) / len(points) 49 | 50 | beta = 25 * pi / 180 #Increasing this constant ROTATES all the labels CLOCKWISE in DEGREES 51 | 52 | p = [ 53 | cos(beta) * old_p[0] - sin(beta) * old_p[1], 54 | sin(beta) * old_p[0] + cos(beta) * old_p[1], 55 | old_p[2] 56 | ] 57 | 58 | # Ok, here's how the logarithmic spiral logic works: 59 | # The distance parameter is divided by a constant; that determines how 60 | # far to pull the point into the spiral. 61 | # 62 | # The second division scales all the points by a constant. 63 | p[0] = (p[0] / pow(e, phi) - distance / 15) / 1.5 64 | p[1] = (p[1] / pow(e, phi) - distance / 15) / 1.5 65 | 66 | i += 1 67 | 68 | return allen_key_profile(key_dia)\ 69 | .translate(tuple(p))\ 70 | .translate((0, 0, -gridfinity.block_cut_limit(depth))) 71 | 72 | return inner 73 | 74 | def decimal_to_binary_fraction(val): 75 | """Convert a decimal value into a binary fraction. 76 | 77 | Fractions are returned as a 3-tuple of (whole, numerator, denominator). 78 | 79 | This works by trial division; we try every power of two up to 256 and 80 | accept the lowest value with no remainder. If there is no fractional 81 | representation of the value, we return the original value.""" 82 | 83 | whole = floor(val) 84 | frac = val - whole 85 | denominator = 2 86 | while denominator < 512: 87 | numerator = frac * denominator 88 | 89 | if abs(numerator - floor(numerator)) < 0.0001: 90 | return (whole, floor(numerator), floor(denominator)) 91 | 92 | denominator *= 2 93 | 94 | return val 95 | 96 | def frac_text(self, whole_txt, numerator_txt, denominator_txt, fontsize, 97 | distance, cut=True, combine=False, clean=True, font="Arial", 98 | fontPath=None, kind='regular', halign='center', valign='center'): 99 | """Generate a solid for a fractional quantity with a whole part, numerator, 100 | and denominator.""" 101 | 102 | if whole_txt.strip() != "": 103 | whole = cq.Compound.makeText(whole_txt, fontsize, distance, font=font, 104 | fontPath=fontPath, kind=kind, halign='left', valign='top', 105 | position=self.plane) 106 | 107 | #TODO: the space width is a guess because Compound.makeText trims strings 108 | whole_width = whole.BoundingBox().xlen + fontsize / 6 109 | else: 110 | whole = cq.Compound.makeCompound([]) 111 | whole_width = 0 112 | 113 | numerator = cq.Compound.makeText(numerator_txt, fontsize / 2, distance, 114 | font=font, fontPath=fontPath, kind=kind, halign='left', valign='top', 115 | position=self.plane) 116 | 117 | numerator_bb = numerator.BoundingBox() 118 | numerator_width = numerator_bb.xmin * 2 + numerator_bb.xlen 119 | #TODO: Check self.plane to see if the coordinates get reversed or not like 120 | #in here 121 | numerator_height = abs(numerator_bb.ymax - numerator_bb.ylen) 122 | 123 | denominator = cq.Compound.makeText(denominator_txt, fontsize / 2, distance, 124 | font=font, fontPath=fontPath, kind=kind, halign='left', valign='top', 125 | position=self.plane) 126 | 127 | denominator_bb = denominator.BoundingBox() 128 | denominator_width = denominator_bb.xmin * 2 + denominator_bb.xlen 129 | 130 | fraction_width = max(numerator_width, denominator_width) 131 | 132 | numerator_offset = (fraction_width - numerator_width) / 2 133 | denominator_offset = (fraction_width - denominator_width) / 2 134 | 135 | #TODO: Figure out how to use the - or emdash from a font without having 136 | #really weird positioning issues. 137 | bar_height = fontsize / 16 138 | bar_spacing = fontsize / 32 139 | bar_y = numerator_height 140 | bar = cq.Workplane(self.plane)\ 141 | .moveTo(0, -bar_y + bar_height / 2)\ 142 | .lineTo(fraction_width, -bar_y + bar_height / 2)\ 143 | .lineTo(fraction_width, -bar_y - bar_height / 2)\ 144 | .lineTo(0, -bar_y - bar_height / 2)\ 145 | .close()\ 146 | .extrude(distance)\ 147 | .val() 148 | 149 | numerator_y = bar_height / 2 + bar_spacing 150 | denominator_y = -numerator_height - bar_height / 2 - bar_spacing 151 | 152 | together = whole\ 153 | .fuse(bar.move(cq.Location(cq.Vector(whole_width, 0, 0))))\ 154 | .fuse(numerator.move(cq.Location(cq.Vector(whole_width + numerator_offset, numerator_y, 0))))\ 155 | .fuse(denominator.move(cq.Location(cq.Vector(whole_width + denominator_offset, denominator_y, 0))))\ 156 | .move(cq.Location(cq.Vector(0, -numerator_y, 0))) 157 | 158 | #TODO: Again, check the workplane for coordinate reversals at some point 159 | together_bb = together.BoundingBox() 160 | together_x = 0 161 | together_y = 0 162 | 163 | if halign == 'center': 164 | together_x = (together_bb.xmin + together_bb.xlen) / 2 165 | elif halign == 'right': 166 | together_x = together_bb.xmin + together_bb.xlen 167 | 168 | if valign == 'center': 169 | together_y = abs(together_bb.ymax + together_bb.ylen) / 2 170 | elif valign == 'right': 171 | together_y = abs(together_bb.ymax + together_bb.ylen) 172 | 173 | together = together.move(cq.Location(cq.Vector(-together_x, together_y, 0))) 174 | 175 | if cut: 176 | combine = 'cut' 177 | 178 | return self._combineWithBase(together, combine, clean) 179 | 180 | cq.Workplane.frac_text = frac_text 181 | 182 | def allen_key_label_generator(points, distance, square_block_size, imperial = False): 183 | """Create an allen key label generator function for use with eachpoint. 184 | 185 | Each generator should only be used once as there is internal closure state 186 | that may not reset properly if reused.""" 187 | 188 | i = 0 189 | 190 | def inner(p): 191 | nonlocal i 192 | 193 | key_dia = points[i % len(points)] 194 | 195 | if imperial: 196 | label_dia = decimal_to_binary_fraction(key_dia) 197 | else: 198 | label_dia = key_dia 199 | 200 | label_base_scale = 0.91 #Increasing this constant pulls numbers at the start of the spiral IN 201 | label_falloff = 0.07 / (len(points) / 5) #Increasing this constant pulls numbers towards the center of the spiral OUT 202 | beta = 65 * pi / 180 #Increasing this constant ROTATES all the labels CLOCKWISE in DEGREES 203 | 204 | #We have a separate spiral scale for big blocks 205 | if square_block_size > 1: 206 | label_base_scale = 0.95 + max(0, 0.045 * (len(points) - 12)) 207 | 208 | #Increasing this constant pulls numbers towards the center of the spiral OUT 209 | label_falloff = 0.01 210 | 211 | #We rotate the big blocks differently because the rotation causes problems with the Ender set 212 | beta = 25 * pi / 180 #Increasing this constant ROTATES all the labels CLOCKWISE in DEGREES 213 | 214 | # Works like the above, except we have an extra scaling term because 215 | # the spiral is too strong 216 | old_p = list(p.toTuple()[0]) 217 | phi = ((i % len(points))) / len(points) 218 | 219 | p = [ 220 | cos(beta) * old_p[0] - sin(beta) * old_p[1], 221 | sin(beta) * old_p[0] + cos(beta) * old_p[1], 222 | old_p[2] 223 | ] 224 | 225 | p[0] = (p[0] / pow(e, phi) - distance / 15) / (label_base_scale - (label_falloff * i)) 226 | p[1] = (p[1] / pow(e, phi) - distance / 15) / (label_base_scale - (label_falloff * i)) 227 | 228 | i += 1 229 | 230 | if type(label_dia) is tuple: 231 | whole = label_dia[0] 232 | if whole == 0: 233 | whole = "" 234 | else: 235 | whole = str(whole) 236 | 237 | nom = str(label_dia[1]) 238 | denom = str(label_dia[2]) 239 | 240 | return cq.Workplane("XY")\ 241 | .frac_text(whole, nom, denom, 10, 2.0, font="Ubuntu", combine="a", halign='left')\ 242 | .val()\ 243 | .translate((p[0], p[1], p[2])) 244 | else: 245 | return cq.Workplane("XY")\ 246 | .text(str(label_dia), 6 - 0.2 * (len(str(label_dia)) - 1), 2.0, font="Ubuntu", combine="a", halign='left')\ 247 | .val()\ 248 | .translate((p[0], p[1], p[2])) 249 | 250 | return inner 251 | 252 | def allen_key_holder(widths, square_block_size, depth, imperial = False): 253 | """Generate a holder for allen keys that can hold one of each listed width 254 | and is a given number of Gridfinity units big and deep. 255 | 256 | The imperial flag does two things: 257 | 258 | * It converts inches to millimeters 259 | * It prints nice-looking binary fractions for the labels""" 260 | 261 | physical_widths = widths 262 | if imperial: 263 | widths.sort(reverse = True) 264 | physical_widths = [width * 25.4 for width in widths] 265 | else: 266 | widths.sort(reverse = True) 267 | physical_widths = widths 268 | 269 | distance = optimal_point_distance(physical_widths) 270 | 271 | return cq.Workplane("XY")\ 272 | .gridfinity_block(square_block_size, square_block_size, depth)\ 273 | .gridfinity_block_stack(square_block_size, square_block_size)\ 274 | .gridfinity_block_lip(square_block_size, square_block_size)\ 275 | .faces(cq.NearestToPointSelector((0, 0, gridfinity.block_top_surface(depth))))\ 276 | .workplane()\ 277 | .polygon(len(physical_widths), distance, forConstruction=True)\ 278 | .vertices()\ 279 | .cutEach(allen_key_cutout_generator(physical_widths, depth, distance))\ 280 | .faces(cq.NearestToPointSelector((0, 0, gridfinity.block_top_surface(depth))))\ 281 | .wires(cq.selectors.InverseSelector(cq.NearestToPointSelector((0, 0, 0))))\ 282 | .fillet(fillet_radius)\ 283 | .faces(cq.NearestToPointSelector((0, 0, gridfinity.block_top_surface(depth))))\ 284 | .workplane()\ 285 | .polygon(len(widths), distance, forConstruction=True)\ 286 | .vertices()\ 287 | .eachpoint(allen_key_label_generator(widths, distance, square_block_size, imperial=imperial), combine="a") 288 | 289 | # Ender 3 ships with an Allen Key set with the following across-flat key sizes: 290 | # 4mm, 3mm, 2.5mm, 2mm, and 1.5mm 291 | # The other sets are all various tool sets I found on Amazon; pick one that 292 | # best matches your current set of keys or add one to the list. 293 | Ender3Set = allen_key_holder([4, 3, 2.5, 2, 1.5], 1, 3) 294 | AmazonBasicsMetric = allen_key_holder([10, 8, 6, 5.5, 5, 4.5, 4, 3.5, 3, 2.5, 2, 1.5, 1.27], 2, 3) 295 | AmazonBasicsImperial = allen_key_holder([3/8, 5/16, 1/4, 7/32, 3/16, 5/32, 9/64, 1/8, 7/64, 3/32, 5/64, 1/16, 0.05], 2, 3, imperial=True) 296 | EPAutoMetric = allen_key_holder([10, 8, 7, 6, 5.5, 5, 4.5, 4, 3, 2.5, 2, 1.5, 1.3, 0.9, 0.7], 2, 3) 297 | EPAutoImperial = allen_key_holder([3/8, 5/16, 1/4, 7/32, 3/16, 5/32, 9/64, 1/8, 7/64, 3/32, 5/64, 1/16, 0.05, 0.035, 0.028], 2, 3, imperial=True) 298 | CraftsmanMetric = allen_key_holder([10, 8, 7, 6, 5, 4, 3, 2.5, 2, 1.5], 2, 3) 299 | CraftsmanImperial = allen_key_holder([3/8, 5/16, 1/4, 7/32, 3/16, 5/32, 1/8, 3/32, 5/64, 1/16], 2, 3, imperial=True) 300 | LichampMetric = allen_key_holder([10, 8, 6, 5, 4, 3, 2.5, 2, 1.5], 2, 3) 301 | LichampImperial = allen_key_holder([3/8, 5/16, 1/4, 3/16, 5/32, 1/8, 3/32, 5/64, 1/16], 2, 3, imperial=True) 302 | 303 | asm = cq.Assembly()\ 304 | .add(Ender3Set, name="Ender3Set")\ 305 | .add(AmazonBasicsMetric, name="AmazonBasicsMetric")\ 306 | .add(AmazonBasicsImperial, name="AmazonBasicsImperial")\ 307 | .add(EPAutoMetric, name="EPAutoMetric")\ 308 | .add(EPAutoImperial, name="EPAutoImperial")\ 309 | .add(CraftsmanMetric, name="CraftsmanMetric")\ 310 | .add(CraftsmanImperial, name="CraftsmanImperial")\ 311 | .add(LichampMetric, name="LichampMetric")\ 312 | .add(LichampImperial, name="LichampImperial")\ 313 | .constrain("Ender3Set@faces@Y")\ 110 | .chamfer(QUILTING_FOOT_WIDTH - QUILTING_FOOT_HOOK_PART_WIDTH)\ 111 | .edges("|Z")\ 112 | .edges(">Y")\ 113 | .fillet(4)\ 114 | .edges("|Z")\ 115 | .edges(">X")\ 116 | .fillet(4) 117 | 118 | etc_holder = etc_holder.cut( 119 | buttonhole_foot.translate((4.5,11,gridfinity.block_top_surface(1))) 120 | ).cut( 121 | quilting_hook_rod.translate((34,-13,gridfinity.block_top_surface(1))) 122 | ).cut( 123 | metal_slab.translate((27,12.25,gridfinity.block_top_surface(1))) 124 | ).cut( 125 | quilting_foot.rotate((0,0,0), (0,0,1), 180)\ 126 | .translate((-10, 13.5, gridfinity.block_top_surface(1))) 127 | ) 128 | 129 | #IT'S FILLETING TIME! 130 | #I swear, fillets are the most painful thing you can do in CQ 131 | etc_holder = etc_holder.edges( 132 | cq.NearestToPointSelector((4.5 + 5, 11, gridfinity.block_top_surface(3))) 133 | ).fillet(1).edges( 134 | cq.NearestToPointSelector((4.5 + 7, 11, gridfinity.block_top_surface(3))) 135 | ).fillet(1).edges( 136 | cq.NearestToPointSelector((4.5 + 9, 11, gridfinity.block_top_surface(3))) 137 | ).fillet(1).edges( 138 | cq.NearestToPointSelector((4.5 - 5, 11, gridfinity.block_top_surface(3))) 139 | ).fillet(1).edges( 140 | cq.NearestToPointSelector((4.5 - 9, 11, gridfinity.block_top_surface(3))) 141 | ).fillet(1).edges( 142 | cq.NearestToPointSelector((4.5, 11 - 3, gridfinity.block_top_surface(3))) 143 | ).fillet(1).edges( 144 | cq.NearestToPointSelector((4.5, 11 + 3, gridfinity.block_top_surface(3))) 145 | ).fillet(1) 146 | 147 | etc_holder = etc_holder.edges( 148 | cq.NearestToPointSelector((34, -13, gridfinity.block_top_surface(3))) 149 | ).fillet(1) 150 | 151 | etc_holder = etc_holder.edges( 152 | cq.NearestToPointSelector((27, 12.25 + 2, gridfinity.block_top_surface(3))) 153 | ).fillet(1).edges( 154 | cq.NearestToPointSelector((27, 12.25 - 2, gridfinity.block_top_surface(3))) 155 | ).fillet(1).edges( 156 | cq.NearestToPointSelector((27 + 8.5, 12.25, gridfinity.block_top_surface(3))) 157 | ).fillet(.99).edges( 158 | cq.NearestToPointSelector((27 - 8.5, 12.25, gridfinity.block_top_surface(3))) 159 | ).fillet(.99) 160 | 161 | # The quilting foot fillets are doubly annoying because we don't even have 162 | # plausible coords for the top edges. 163 | etc_holder = etc_holder.edges( 164 | cq.NearestToPointSelector((-10, 0, gridfinity.block_top_surface(3))) 165 | ).fillet(1).edges( 166 | cq.NearestToPointSelector((-20, 0, gridfinity.block_top_surface(3))) 167 | ).fillet(1).edges( 168 | cq.NearestToPointSelector((-20, 10, gridfinity.block_top_surface(3))) 169 | ).fillet(1).edges( 170 | cq.NearestToPointSelector((-25, 10, gridfinity.block_top_surface(3))) 171 | ).fillet(.99) #For some reason, this fillet breaks. 172 | 173 | etc_holder = etc_holder.edges( 174 | cq.NearestToPointSelector((-10, 0, gridfinity.block_top_surface(1))) 175 | ).fillet(2).edges( 176 | cq.NearestToPointSelector((-25, -5, gridfinity.block_top_surface(1))) 177 | ).fillet(2).edges( 178 | cq.NearestToPointSelector((-19, 15, gridfinity.block_top_surface(1))) 179 | ).fillet(2) 180 | 181 | del buttonhole_foot 182 | del quilting_hook_rod 183 | del metal_slab 184 | del quilting_foot -------------------------------------------------------------------------------- /examples/game_carts/ds.py: -------------------------------------------------------------------------------- 1 | import cadquery as cq 2 | import gridfinity 3 | import math 4 | 5 | #All units are mm 6 | #TODO: Adding the tolerance in the later calculations breaks all the cutout math 7 | 8 | tolerance = 0.75 #used to loosen fit with DS cards 9 | depth_tolerance = 0.25 #ALSO used to loosen fit, but in the thinner Y direction 10 | ds_cart_width = 32.85 11 | ds_cart_height = 34.96 12 | ds_cart_depth = 3.80 13 | 14 | ds_pcb_depth = 2.52 15 | ds_pins_width = 25 16 | ds_pins_height = 10.56 17 | 18 | ds_pins_x_left = 3.12 19 | ds_pins_x_right = 4.18 20 | 21 | ds_fillet_radius = 0.5 22 | ds_wide_fillet_radius = 3 23 | 24 | #3DS carts have an extra tab on the top right to prevent insertion into a DS/DSi 25 | #We construct a 3DS profile purely so I can make sure the tab doesn't intersect 26 | #with the holder. 27 | threeds_tab_width = 34.92 - ds_cart_width 28 | threeds_tab_height = 6.45 29 | 30 | threeds_cart_profile = cq.Sketch()\ 31 | .segment(((ds_cart_width + tolerance / 2) / 2 + threeds_tab_width, (ds_cart_height + tolerance) / 2), 32 | ((ds_cart_width + tolerance / 2) / 2 + threeds_tab_width, (ds_cart_height + tolerance) / 2 - threeds_tab_height))\ 33 | .segment(((ds_cart_width + tolerance / 2) / 2, (ds_cart_height + tolerance) / 2 - threeds_tab_height))\ 34 | .segment(((ds_cart_width + tolerance / 2) / 2, (ds_cart_height + tolerance) / -2))\ 35 | .segment(((ds_cart_width + tolerance / 2) / -2, (ds_cart_height + tolerance) / -2))\ 36 | .segment(((ds_cart_width + tolerance / 2) / -2, (ds_cart_height + tolerance) / 2))\ 37 | .close()\ 38 | .assemble(tag='face')\ 39 | .vertices(">(-10, -10, 0)")\ 40 | .fillet(ds_wide_fillet_radius)\ 41 | .faces()\ 42 | .vertices()\ 43 | .fillet(ds_fillet_radius) 44 | 45 | threeds_pins_profile = cq.Sketch()\ 46 | .rect(ds_pins_width - tolerance, ds_pins_height + tolerance)\ 47 | .moved(cq.Location(cq.Vector(ds_pins_width / -2 - ds_cart_width / -2 - ds_pins_x_left, ds_pins_height / 2 - ds_cart_height / 2 - tolerance))) 48 | 49 | threeds_cart = cq.Workplane("XZ")\ 50 | .placeSketch(threeds_cart_profile)\ 51 | .extrude(ds_cart_depth + depth_tolerance)\ 52 | .faces("|Y and X")\ 40 | .edges("|Z")\ 41 | .chamfer(gb_chamfer_radius)\ 42 | .faces(">Z")\ 43 | .workplane()\ 44 | .center(gb_cart_depth / 2, 0)\ 45 | .rect(gb_cart_depth, gb_cart_width + tolerance)\ 46 | .extrude(gb_cart_height - gb_chamfer_length)\ 47 | .faces("X")\ 53 | .workplane()\ 54 | .center((gb_cart_width + tolerance) / 2 - gb_cutout_width / 2, gb_cart_height + tolerance - gb_cutout_height / 2)\ 55 | .rect(gb_cutout_width, gb_cutout_height)\ 56 | .cutThruAll()\ 57 | .translate([-gb_cart_depth, 0, 0])\ 58 | .rotate([0, 0, 0], [0, 0, 1], 270) 59 | 60 | gba_cart_height = 34.70 61 | 62 | # GBA has a slightly narrowed inner slot cutout to prevent insertion into 63 | # earlier consoles. 64 | gba_narrow_slot_width = 51.28 # measured inside the slot 65 | gba_narrow_slot_depth = 4.05 # measured from back of cartridge to slot 66 | 67 | # GBA cartridges also have a top lip which makes the cartridge slightly wider 68 | # at the top. 69 | gba_lip_width = 60.10 70 | gba_lip_height = 7.11 71 | 72 | gba_cart = cq.Workplane("YZ")\ 73 | .moveTo((gba_lip_width + tolerance) / 2, (gba_cart_height + tolerance) / 2)\ 74 | .lineTo((gba_lip_width + tolerance) / 2, (gba_cart_height + tolerance) / 2 - gba_lip_height)\ 75 | .lineTo((gb_cart_width + tolerance) / 2, (gba_cart_height + tolerance) / 2 - gba_lip_height)\ 76 | .lineTo((gb_cart_width + tolerance) / 2, (gba_cart_height + tolerance) / -2)\ 77 | .lineTo((gb_cart_width + tolerance) / -2, (gba_cart_height + tolerance) / -2)\ 78 | .lineTo((gb_cart_width + tolerance) / -2, (gba_cart_height + tolerance) / 2 - gba_lip_height)\ 79 | .lineTo((gba_lip_width + tolerance) / -2, (gba_cart_height + tolerance) / 2 - gba_lip_height)\ 80 | .lineTo((gba_lip_width + tolerance) / -2, (gba_cart_height + tolerance) / 2)\ 81 | .close()\ 82 | .extrude(gb_cart_depth)\ 83 | .faces("X")\ 97 | .edges(">(0, 1, -1) or >(0, -1, -1)")\ 98 | .chamfer(gb_chamfer_radius)\ 99 | .edges("#Y and >Z")\ 100 | .fillet(gb_chamfer_radius)\ 101 | .faces(">X")\ 102 | .edges(">Y or Z")\ 103 | .chamfer(gb_chamfer_radius)\ 104 | .translate([-gb_cart_depth, 0, (gb_chamfer_length + tolerance) / -2 + (gba_cart_height + tolerance) / 2])\ 105 | .rotate([0, 0, 0], [0, 0, 1], 270) 106 | 107 | # The above models are nice for illustrations... but if I just cut them 108 | # straight into a block, we'll get a nice impression of the chamfers that I 109 | # don't want. 110 | # 111 | # Instead, here's a 'simplified' version that lacks the chamfers. 112 | union_cart = cq.Workplane("YZ")\ 113 | .moveTo((gba_lip_width + tolerance) / 2, (gba_cart_height + tolerance) / 2)\ 114 | .lineTo((gba_lip_width + tolerance) / 2, (gba_cart_height + tolerance) / 2 - gba_lip_height)\ 115 | .lineTo((gb_cart_width + tolerance) / 2, (gba_cart_height + tolerance) / 2 - gba_lip_height)\ 116 | .lineTo((gb_cart_width + tolerance) / 2, (gba_cart_height + tolerance) / -2)\ 117 | .lineTo((gb_cart_width + tolerance) / -2, (gba_cart_height + tolerance) / -2)\ 118 | .lineTo((gb_cart_width + tolerance) / -2, (gba_cart_height + tolerance) / 2 - gba_lip_height)\ 119 | .lineTo((gba_lip_width + tolerance) / -2, (gba_cart_height + tolerance) / 2 - gba_lip_height)\ 120 | .lineTo((gba_lip_width + tolerance) / -2, (gba_cart_height + tolerance) / 2)\ 121 | .close()\ 122 | .extrude(gb_cart_depth)\ 123 | .faces("Z")\ 65 | .placeSketch(staedtler_profile.moved(cq.Location(cq.Vector((3,0,0)))))\ 66 | .cutBlind(-10)\ 67 | .translate((gridfinity.grid_unit * 2.5, 0, 0)) 68 | 69 | #It's called the "china ruler" because that's the only identifying mark on the 70 | #tool. It's a thin ruler with a big square lip in the middle of the profile for 71 | #what I presume is making it easier to grab. 72 | china_ruler_width = 30 + tolerance #mm 73 | 74 | china_ruler_thickness = 2.40 + tolerance #mm 75 | 76 | china_ruler_lip_width = 8.74 + tolerance #mm 77 | 78 | china_ruler_lip_thickness = 11.75 + tolerance #mm 79 | 80 | china_ruler_lip_width_top = 5.5 + tolerance #mm 81 | 82 | china_profile = cq.Sketch()\ 83 | .segment((china_ruler_width / -2, 0), (china_ruler_width / 2, 0))\ 84 | .segment((china_ruler_width / 2, china_ruler_thickness))\ 85 | .segment((china_ruler_lip_width / 2, china_ruler_thickness))\ 86 | .segment((china_ruler_lip_width_top / 2, china_ruler_lip_thickness))\ 87 | .segment((china_ruler_lip_width_top / -2, china_ruler_lip_thickness))\ 88 | .segment((china_ruler_lip_width / -2, china_ruler_thickness))\ 89 | .segment((china_ruler_width / -2, china_ruler_thickness))\ 90 | .close()\ 91 | .assemble()\ 92 | .vertices(cq.NearestToPointSelector((china_ruler_width / 2, 0)))\ 93 | .fillet(1)\ 94 | .reset()\ 95 | .vertices(cq.NearestToPointSelector((china_ruler_width / -2, 0)))\ 96 | .fillet(1)\ 97 | .reset()\ 98 | .vertices(cq.NearestToPointSelector((china_ruler_width / 2, china_ruler_thickness)))\ 99 | .fillet(1)\ 100 | .reset()\ 101 | .vertices(cq.NearestToPointSelector((china_ruler_width / -2, china_ruler_thickness)))\ 102 | .fillet(1)\ 103 | .reset()\ 104 | .vertices(cq.NearestToPointSelector((china_ruler_lip_width_top / 2, china_ruler_lip_thickness)))\ 105 | .fillet(0.75)\ 106 | .reset()\ 107 | .vertices(cq.NearestToPointSelector((china_ruler_lip_width_top / -2, china_ruler_lip_thickness)))\ 108 | .fillet(0.75)\ 109 | .reset()\ 110 | .vertices(cq.NearestToPointSelector((china_ruler_lip_width / 2, 0)))\ 111 | .fillet(3)\ 112 | .reset()\ 113 | .vertices(cq.NearestToPointSelector((china_ruler_lip_width_top / -2, china_ruler_thickness)))\ 114 | .fillet(3)\ 115 | .reset() 116 | 117 | china_ruler = cq.Workplane("XY")\ 118 | .gridfinity_block(1, 1, 6)\ 119 | .gridfinity_block_stack(1, 1)\ 120 | .gridfinity_block_lip(1, 1)\ 121 | .gridfinity_top_face(6)\ 122 | .workplane()\ 123 | .transformed(offset=(-2, 2, 0), rotate=(0, 0, 45))\ 124 | .placeSketch(china_profile.moved(cq.Location(cq.Vector((0,0,0)))))\ 125 | .cutBlind(gridfinity.block_cut_limit(6) * -1)\ 126 | .transformed(rotate=(0, 0, -45))\ 127 | .transformed(offset=(2, -2, 0))\ 128 | .transformed(offset=(2, -2, 0), rotate=(0, 0, -135))\ 129 | .placeSketch(china_profile.moved(cq.Location(cq.Vector((0,0,0)))))\ 130 | .cutBlind(gridfinity.block_cut_limit(6) * -1)\ 131 | .edges(cq.NearestToPointSelector((5,0,gridfinity.block_top_surface(6))))\ 132 | .fillet(1.5)\ 133 | .edges(cq.NearestToPointSelector((-5,0,gridfinity.block_top_surface(6))))\ 134 | .fillet(1.5)\ 135 | .edges(cq.NearestToPointSelector((5,0,gridfinity.block_top_surface(6) - gridfinity.block_cut_limit(6))))\ 136 | .fillet(0.5)\ 137 | .edges(cq.NearestToPointSelector((-5,0,gridfinity.block_top_surface(6) - gridfinity.block_cut_limit(6))))\ 138 | .fillet(0.5)\ 139 | .translate((gridfinity.grid_unit * -1, 0, 0)) 140 | 141 | #Test jig for the china ruler profile fit 142 | china_test = cq.Workplane("XY")\ 143 | .rect(china_ruler_width + 5, china_ruler_lip_thickness + 5)\ 144 | .extrude(1)\ 145 | .faces(">Z")\ 146 | .placeSketch(china_profile 147 | .moved(cq.Location(cq.Vector((0, -china_ruler_lip_thickness / 2,0)))) 148 | )\ 149 | .cutBlind(-10)\ 150 | .translate((gridfinity.grid_unit * -2.5, 0, 0)) -------------------------------------------------------------------------------- /examples/sewing_feet_holder.py: -------------------------------------------------------------------------------- 1 | import cadquery as cq 2 | import gridfinity 3 | 4 | G_FOOT_WIDTH = 15.81 5 | R_FOOT_WIDTH = 15.95 6 | X_FOOT_WIDTH = 16.90 7 | I_FOOT_WIDTH = 17.48 8 | I_FOOT_WIDTH_TAB = 9.49 9 | M_FOOT_WIDTH = 17.66 10 | N_FOOT_WIDTH = 19.60 11 | 12 | # Measured on the "R" foot, which is the thickest. 13 | # Rounded up for 3D printing tolerance. 14 | # Other feet are closer to 8mm. 15 | FOOT_THICKNESS = 11 #10.15 16 | 17 | # R foot has a piece of metal that sticks beyond the profile of the foot, 18 | # so we have to make a cutout for it. 19 | R_FOOT_FIN_CUTOUT_X = 8.11 20 | R_FOOT_FIN_CUTOUT_WIDTH = 2.5 21 | 22 | G_FOOT_FIN_CUTOUT_WIDTH = 6.2 #5.86 23 | 24 | sewing_foot_block = cq.Workplane("XY")\ 25 | .gridfinity_block(2, 1, 3)\ 26 | .gridfinity_block_stack(2, 1)\ 27 | .gridfinity_block_lip(2, 1) 28 | 29 | SPACING_X = 8 30 | SPACING_Y = 6 31 | 32 | SLOT_FILLET = 1 33 | 34 | for i in range(0, 3): 35 | for j in range(0, 2): 36 | if i == 0 and j == 1: 37 | FOOT_WIDTH = N_FOOT_WIDTH + 0.5 38 | elif i == 1 and j == 0: 39 | FOOT_WIDTH = X_FOOT_WIDTH + 0.5 40 | elif i == 1 and j == 1: 41 | FOOT_WIDTH = I_FOOT_WIDTH_TAB + 0.5 42 | elif i == 2: 43 | FOOT_WIDTH = R_FOOT_WIDTH + 0.5 44 | else: 45 | FOOT_WIDTH = M_FOOT_WIDTH + 0.5 46 | 47 | z_coord = 3 * j 48 | 49 | sewing_foot = cq.Workplane("XY")\ 50 | .rect(FOOT_WIDTH, FOOT_THICKNESS)\ 51 | .extrude(FOOT_WIDTH * 2)\ 52 | .translate([0, 0, 2]) 53 | 54 | x_coord = (M_FOOT_WIDTH + SPACING_X) * (i - 1) 55 | y_coord = (FOOT_THICKNESS + SPACING_Y) * (j - 0.5) 56 | 57 | if i == 0 and j == 1: #N foot compartment 58 | x_coord -= (M_FOOT_WIDTH - FOOT_WIDTH) / 2 59 | 60 | sewing_foot_block = sewing_foot_block.cut( 61 | sewing_foot.translate( 62 | [x_coord, 63 | y_coord, 64 | z_coord] 65 | ) 66 | ).edges( 67 | cq.NearestToPointSelector((x_coord + 8, 68 | y_coord, 69 | gridfinity.block_top_surface(3))) 70 | ).fillet(SLOT_FILLET)\ 71 | .edges( 72 | cq.NearestToPointSelector((x_coord - 8, 73 | y_coord, 74 | gridfinity.block_top_surface(3))) 75 | ).fillet(SLOT_FILLET)\ 76 | .edges( 77 | cq.NearestToPointSelector((x_coord, 78 | y_coord + 4, 79 | gridfinity.block_top_surface(3))) 80 | ).fillet(SLOT_FILLET)\ 81 | .edges( 82 | cq.NearestToPointSelector((x_coord, 83 | y_coord - 4, 84 | gridfinity.block_top_surface(3))) 85 | ).fillet(SLOT_FILLET)\ 86 | .edges( 87 | cq.NearestToPointSelector((x_coord, 88 | y_coord + 0.5, 89 | 3 * j)) 90 | ).fillet(FOOT_THICKNESS - SLOT_FILLET) 91 | 92 | if i == 2 and j == 0: 93 | #The R foot's metal fin is near enough to the center that 94 | #I don't feel like doing the parametric math to properly 95 | #offset it. 96 | cutout_block = cq.Workplane("XY")\ 97 | .rect(R_FOOT_FIN_CUTOUT_WIDTH, FOOT_THICKNESS + 2.5)\ 98 | .extrude(FOOT_WIDTH * 2)\ 99 | .translate([x_coord, y_coord - 1.25, 0]) 100 | 101 | sewing_foot_block = sewing_foot_block.cut(cutout_block)\ 102 | .edges( 103 | cq.NearestToPointSelector((x_coord + 1, y_coord - 6, gridfinity.block_top_surface(3))) 104 | )\ 105 | .fillet(SLOT_FILLET)\ 106 | .edges( 107 | cq.NearestToPointSelector((x_coord - 1, y_coord - 6, gridfinity.block_top_surface(3))) 108 | )\ 109 | .fillet(SLOT_FILLET)\ 110 | .edges( 111 | cq.NearestToPointSelector((x_coord, y_coord - 7, gridfinity.block_top_surface(3))) 112 | )\ 113 | .fillet(SLOT_FILLET) 114 | 115 | if i == 2 and j == 1: 116 | #The G foot is only half-curved at the front. 117 | cutout_block = cq.Workplane("XY")\ 118 | .rect(G_FOOT_FIN_CUTOUT_WIDTH, FOOT_THICKNESS)\ 119 | .extrude(FOOT_WIDTH * 2)\ 120 | .translate([x_coord + FOOT_WIDTH / 2 - G_FOOT_FIN_CUTOUT_WIDTH / 2, y_coord, 1.75]) 121 | 122 | sewing_foot_block = sewing_foot_block.cut(cutout_block) 123 | 124 | del cutout_block 125 | del sewing_foot -------------------------------------------------------------------------------- /examples/tube_holders.py: -------------------------------------------------------------------------------- 1 | import cadquery as cq 2 | import gridfinity, math 3 | 4 | FUDGE_FACTOR = 0.25 5 | 6 | def cut_at(tube, block, point): 7 | return block\ 8 | .cut(tube.translate(point))\ 9 | .edges( 10 | cq.NearestToPointSelector((point[0], point[1], gridfinity.block_top_surface(1))) 11 | )\ 12 | .fillet(2)\ 13 | .edges( 14 | cq.NearestToPointSelector((point[0], point[1], gridfinity.block_top_surface(3))) 15 | )\ 16 | .fillet(1) 17 | 18 | def tube_holder(dia): 19 | size = 1 20 | if dia > 35: 21 | size = 2 22 | 23 | if dia > 77: 24 | size = 3 25 | 26 | size_mm = size * gridfinity.grid_unit 27 | 28 | tube = cq.Workplane("XY")\ 29 | .circle((dia + FUDGE_FACTOR) / 2)\ 30 | .extrude(100)\ 31 | .translate((0,0,gridfinity.block_top_surface(1))) 32 | 33 | block = cq.Workplane("XY")\ 34 | .gridfinity_block(size,size,3)\ 35 | .gridfinity_block_stack(size,size)\ 36 | .gridfinity_block_lip(size,size) 37 | 38 | if dia <= 12: 39 | quincunx_dist = size_mm / 4 40 | 41 | block = cut_at(tube, block, (0, 0, 0)) 42 | block = cut_at(tube, block, (quincunx_dist, quincunx_dist, 0)) 43 | block = cut_at(tube, block, (-quincunx_dist, -quincunx_dist, 0)) 44 | block = cut_at(tube, block, (-quincunx_dist, quincunx_dist, 0)) 45 | block = cut_at(tube, block, (quincunx_dist, -quincunx_dist, 0)) 46 | elif (size_mm - gridfinity.block_mating_inset) > dia * 2: 47 | quincunx_dist = size_mm / 5.5 48 | 49 | block = cut_at(tube, block, (quincunx_dist, quincunx_dist, 0)) 50 | block = cut_at(tube, block, (-quincunx_dist, -quincunx_dist, 0)) 51 | else: 52 | block = block\ 53 | .cut(tube)\ 54 | .edges( 55 | cq.NearestToPointSelector((0, 0, gridfinity.block_top_surface(1))) 56 | )\ 57 | .fillet(2)\ 58 | .edges( 59 | cq.NearestToPointSelector((0, 0, gridfinity.block_top_surface(3))) 60 | )\ 61 | .fillet(1) 62 | 63 | return block 64 | 65 | for i in range(5, 78): 66 | interval = 1.5 67 | index = i - 5 68 | y = 0 69 | xstride = 8 70 | 71 | if i > 35: 72 | interval = 2 73 | index = i - 36 74 | y = gridfinity.grid_unit * 6 75 | xstride = 6 76 | 77 | locals()[str(i) + "mm Tube Holder"] = tube_holder(i)\ 78 | .translate((index % xstride * gridfinity.grid_unit * interval, 79 | y + math.floor(index / xstride) * gridfinity.grid_unit * interval, 80 | 0)) -------------------------------------------------------------------------------- /examples/walking_foot_holder.py: -------------------------------------------------------------------------------- 1 | """Holder for the walking foot that came with my Brother CS7000X""" 2 | 3 | import cadquery as cq 4 | import gridfinity 5 | 6 | walking_foot_block = cq.Workplane("XY")\ 7 | .gridfinity_block(1, 1, 3)\ 8 | .gridfinity_block_stack(1, 1)\ 9 | .gridfinity_block_lip(1, 1) 10 | 11 | FUDGE_FACTOR = 0.5 12 | 13 | WALKING_FOOT_WIDTH = 19.62 + FUDGE_FACTOR 14 | WALKING_FOOT_HEIGHT = 27.35 + FUDGE_FACTOR 15 | WALKING_FOOT_DEPTH = 42.56 + FUDGE_FACTOR 16 | 17 | walking_foot = cq.Workplane("XY")\ 18 | .rect(WALKING_FOOT_WIDTH, WALKING_FOOT_HEIGHT)\ 19 | .extrude(WALKING_FOOT_DEPTH)\ 20 | .edges(">Y")\ 21 | .edges("Z face. 157 | 158 | Face dimensions must match the width and height given here.""" 159 | 160 | depth = self.faces(">Z").val().Center().toTuple()[2] 161 | 162 | inset = cq.Workplane("XY")\ 163 | .placeSketch(inset_profile(width, height, block_mating_inset))\ 164 | .extrude(stacking_mating_depth * -1)\ 165 | .translate([0, 0, depth]) 166 | 167 | return self.faces(">Z")\ 168 | .cut(inset)\ 169 | .edges(cq.NearestToPointSelector([0, 0, depth]))\ 170 | .chamfer(block_mating_inset - block_spacing * 0.5 - block_stacking_lip)\ 171 | .edges(cq.NearestToPointSelector([0, 0, depth - block_mating_depth]))\ 172 | .chamfer(block_stacking_chamfer)\ 173 | .edges(cq.NearestToPointSelector([width * grid_unit / 2, height * grid_unit / 2, depth + 10]))\ 174 | .fillet(block_stacking_lip / 2)\ 175 | .edges(cq.NearestToPointSelector([width * grid_unit / 2 - block_stacking_lip * 4, height * grid_unit / 2 - block_stacking_lip * 4, depth + 2]))\ 176 | .fillet(block_stacking_lip) 177 | 178 | cq.Workplane.gridfinity_block_stack = gridfinity_block_stack 179 | 180 | def gridfinity_block_lip(self, width, height, screw_depth=screw_depth, holes=True): 181 | """Extrude Gridfinity block mating lip out of the