|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 3, |
| 6 | + "id": "streaming-trinity", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [ |
| 9 | + { |
| 10 | + "name": "stdout", |
| 11 | + "output_type": "stream", |
| 12 | + "text": [ |
| 13 | + "Overwriting auto display for cadquery Workplane and Shape\n" |
| 14 | + ] |
| 15 | + } |
| 16 | + ], |
| 17 | + "source": [ |
| 18 | + "import warnings\n", |
| 19 | + "warnings.filterwarnings(\"ignore\")\n", |
| 20 | + "\n", |
| 21 | + "import cadquery as cq\n", |
| 22 | + "from jupyter_cadquery.cadquery import show\n", |
| 23 | + "\n", |
| 24 | + "from cadquery.occ_impl import exporters\n", |
| 25 | + "\n", |
| 26 | + "def make_block(lbumps, wbumps, thin):\n", |
| 27 | + "# lbumps = 4 # number of bumps long\n", |
| 28 | + "# wbumps = 2 # number of bumps wide\n", |
| 29 | + "# thin = False # True for thin, False for thick\n", |
| 30 | + "\n", |
| 31 | + " #\n", |
| 32 | + " # Lego Brick Constants-- these make a Lego brick a Lego :)\n", |
| 33 | + " #\n", |
| 34 | + " pitch = 8.0\n", |
| 35 | + " clearance = 0.1\n", |
| 36 | + " bumpDiam = 4.8\n", |
| 37 | + " bumpHeight = 1.8\n", |
| 38 | + " if thin:\n", |
| 39 | + " height = 3.2\n", |
| 40 | + " else:\n", |
| 41 | + " height = 9.6\n", |
| 42 | + "\n", |
| 43 | + " t = (pitch - (2 * clearance) - bumpDiam) / 2.0\n", |
| 44 | + " postDiam = pitch - t # works out to 6.5\n", |
| 45 | + " total_length = lbumps*pitch - 2.0*clearance\n", |
| 46 | + " total_width = wbumps*pitch - 2.0*clearance\n", |
| 47 | + "\n", |
| 48 | + " # make the base\n", |
| 49 | + " s = cq.Workplane(\"XY\").box(total_length, total_width, height)\n", |
| 50 | + "\n", |
| 51 | + " # shell inwards not outwards\n", |
| 52 | + " s = s.faces(\"<Z\").shell(-1.0 * t)\n", |
| 53 | + "\n", |
| 54 | + " # make the bumps on the top\n", |
| 55 | + " s = (s.faces(\">Z\").workplane().\n", |
| 56 | + " rarray(pitch, pitch, lbumps, wbumps, True).circle(bumpDiam / 2.0)\n", |
| 57 | + " .extrude(bumpHeight))\n", |
| 58 | + "\n", |
| 59 | + " # add posts on the bottom. posts are different diameter depending on geometry\n", |
| 60 | + " # solid studs for 1 bump, tubes for multiple, none for 1x1\n", |
| 61 | + " tmp = s.faces(\"<Z\").workplane(invert=True)\n", |
| 62 | + "\n", |
| 63 | + " if lbumps > 1 and wbumps > 1:\n", |
| 64 | + " tmp = (tmp.rarray(pitch, pitch, lbumps - 1, wbumps - 1, center=True).\n", |
| 65 | + " circle(postDiam / 2.0).circle(bumpDiam / 2.0).extrude(height - t))\n", |
| 66 | + " elif lbumps > 1:\n", |
| 67 | + " tmp = (tmp.rarray(pitch, pitch, lbumps - 1, 1, center=True).\n", |
| 68 | + " circle(t).extrude(height - t))\n", |
| 69 | + " elif wbumps > 1:\n", |
| 70 | + " tmp = (tmp.rarray(pitch, pitch, 1, wbumps - 1, center=True).\n", |
| 71 | + " circle(t).extrude(height - t))\n", |
| 72 | + " else:\n", |
| 73 | + " tmp = s\n", |
| 74 | + " \n", |
| 75 | + " return tmp" |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "code", |
| 80 | + "execution_count": 4, |
| 81 | + "id": "agricultural-blend", |
| 82 | + "metadata": {}, |
| 83 | + "outputs": [ |
| 84 | + { |
| 85 | + "data": { |
| 86 | + "application/vnd.jupyter.widget-view+json": { |
| 87 | + "model_id": "69757b311cce40d2b6bf5d02764171e5", |
| 88 | + "version_major": 2, |
| 89 | + "version_minor": 0 |
| 90 | + }, |
| 91 | + "text/plain": [ |
| 92 | + "HBox(children=(VBox(children=(HBox(children=(Checkbox(value=False, description='Axes', indent=False, _dom_clas…" |
| 93 | + ] |
| 94 | + }, |
| 95 | + "metadata": {}, |
| 96 | + "output_type": "display_data" |
| 97 | + }, |
| 98 | + { |
| 99 | + "data": { |
| 100 | + "text/plain": [ |
| 101 | + "<jupyter_cadquery.cad_display.CadqueryDisplay at 0x7fa806d74a60>" |
| 102 | + ] |
| 103 | + }, |
| 104 | + "execution_count": 4, |
| 105 | + "metadata": {}, |
| 106 | + "output_type": "execute_result" |
| 107 | + } |
| 108 | + ], |
| 109 | + "source": [ |
| 110 | + "block = make_block(2, 2, True)\n", |
| 111 | + "show(block)" |
| 112 | + ] |
| 113 | + } |
| 114 | + ], |
| 115 | + "metadata": { |
| 116 | + "kernelspec": { |
| 117 | + "display_name": "Python 3", |
| 118 | + "language": "python", |
| 119 | + "name": "python3" |
| 120 | + }, |
| 121 | + "language_info": { |
| 122 | + "codemirror_mode": { |
| 123 | + "name": "ipython", |
| 124 | + "version": 3 |
| 125 | + }, |
| 126 | + "file_extension": ".py", |
| 127 | + "mimetype": "text/x-python", |
| 128 | + "name": "python", |
| 129 | + "nbconvert_exporter": "python", |
| 130 | + "pygments_lexer": "ipython3", |
| 131 | + "version": "3.8.5" |
| 132 | + } |
| 133 | + }, |
| 134 | + "nbformat": 4, |
| 135 | + "nbformat_minor": 5 |
| 136 | +} |
0 commit comments