From 646a0e57e964c1476bb11799d8d98efa6f41e5d2 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Mon, 10 Sep 2018 09:57:58 +0200 Subject: [PATCH] New Jupyter notebook with an example generator --- scripts/boxes_example.ipynb | 150 ++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 scripts/boxes_example.ipynb diff --git a/scripts/boxes_example.ipynb b/scripts/boxes_example.ipynb new file mode 100644 index 0000000..9dbc2b5 --- /dev/null +++ b/scripts/boxes_example.ipynb @@ -0,0 +1,150 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Boxes.py example\n", + "\n", + "This notebook is an interactive example of a Boxes.py generator. Feel free to play around and see how the result changes.\n", + "\n", + "Check out http://florianfesti.github.io/boxes/html/index.html for documentation." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from IPython.display import SVG, display\n", + "\n", + "import sys\n", + "#sys.path.append('/PATH/TO/boxes') # uncomments and adjust if your Boxes.py copy in not in the Python path\n", + "from boxes import *" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "class Example(Boxes): # Adjust class name and call below\n", + " \"\"\"Example: Single Shelve to screw to the wall\"\"\"\n", + "\n", + " ui_group = \"Shelves\" # change for generators belonging in another group\n", + " \n", + " def __init__(self):\n", + " Boxes.__init__(self)\n", + " # arguments\n", + " self.addSettingsArgs(edges.FingerJointSettings, finger=3.0) # arguments for finger joints\n", + " self.buildArgParser(x=150, y=70, h=50)\n", + " self.argparser.add_argument(\n", + " \"--hole_dist\", action=\"store\", type=float, default=10.,\n", + " help=\"distance of the mounting holes to the boards\")\n", + " self.argparser.add_argument(\n", + " \"--hole_dia\", action=\"store\", type=float, default=3., # can't use \"hole\" as param name as it is a method\n", + " help=\"diameter of the mounting holes\")\n", + " \n", + " def render(self):\n", + " x, y, h = self.x, self.y, self.h\n", + " t = self.thickness\n", + " self.open()\n", + " \n", + " # render-magic goes here\n", + " \n", + " hole = lambda: self.hole(self.hole_dist, self.hole_dist, d=self.hole_dia) # use lambda as a callback\n", + " # holes are placed relative to the inner rectangle of the back wall. The top part with the finger holes and \n", + " # the finges at the sides do not count.\n", + " # Callbacks start in the bottom left corner. Place holes in the third and forth corners only. \n", + " self.rectangularWall(x, h, \"eFhF\", move=\"up\", callback=[None, None, hole, hole]) # back board\n", + "\n", + " self.rectangularWall(x, y, \"ehfh\", move=\"up\") # top board\n", + " self.rectangularTriangle(y, h, \"ff\", num=2) # braces\n", + " \n", + " \n", + " self.close()\n", + "\n", + "b = Example()\n", + "b.parseArgs(['--reference=0', '--debug=0'])\n", + "b.render()\n", + "\n", + "display(SVG(b.output))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}