{
"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": 4,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import SVG, display\n",
"\n",
"import sys\n",
"# sys.path.append('..') # uncomments and adjust if your Boxes.py copy in not in the Python path\n",
"from boxes import *"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"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",
" \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",
"b = Example()\n",
"b.parseArgs(['--reference=0', '--debug=0'])\n",
"b.open()\n",
"b.render()\n",
"data = b.close()\n",
"\n",
"display(SVG(data=data.getvalue()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.12.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}