{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import cadquery as cq\n", "from jupyter_cadquery import (\n", " open_viewer, show, show_object,\n", " set_defaults, get_defaults, \n", ")\n", "from cadquery_massembly import Mate, MAssembly, relocate\n", "\n", "cv = open_viewer(\"Door\")\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "set_defaults(axes=False, axes0=True, mate_scale=10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Note:** Download https://www.matronics.dk/data/longship/files/products/vslot-2020_1.dxf first if you don't have it at hand" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Parameters\n", "H = 400\n", "W = 200\n", "D = 350\n", "\n", "PROFILE = cq.importers.importDXF(\"vslot-2020_1.dxf\").wires()\n", "\n", "SLOT_D = 6\n", "PANEL_T = 3\n", "\n", "HANDLE_D = 20\n", "HANDLE_L = 50\n", "HANDLE_W = 4" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def make_vslot(l):\n", "\n", " return PROFILE.toPending().extrude(l)\n", "\n", "\n", "def make_connector():\n", "\n", " rv = (\n", " cq.Workplane()\n", " .box(20, 20, 20)\n", " .faces(\"X\").tag(\"X\").end()\n", " rv.faces(\">Z\").tag(\"Z\").end()\n", "\n", " return rv\n", "\n", "\n", "def make_panel(w, h, t, cutout):\n", "\n", " rv = (\n", " cq.Workplane(\"XZ\")\n", " .rect(w, h)\n", " .extrude(t)\n", " .faces(\">Y\")\n", " .vertices()\n", " .rect(2*cutout,2*cutout)\n", " .cutThruAll()\n", " .faces(\"Z\").tag(\"hole1\")\n", " rv.faces(\"Y\").tag(\"mate1\")\n", " rv.faces(\"Z\", name=f\"{v}_0\", transforms=odict(rx=0))\n", " door.mate(f\"{v}@faces@X[-4]\", name=\"panel_1\")\n", "\n", "# add mates to handle and one hole\n", "door.mate(\"handle?mate1\", name=\"handle_0\", transforms=odict(rx=180))\n", "door.mate(\"panel?hole2\", name=\"handle_1\", transforms=odict(rx=180))\n", "\n", "show(door, render_mates=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# manually assemble as you would in reality\n", "\n", "door.assemble(\"bottom_0\", \"con_bl_0\") # add bottom vslot to bottom-left connector\n", "door.assemble(\"con_br_1\", \"bottom_1\") # add bottom-right connector to bottom vslot\n", "door.assemble(\"left_1\", \"con_bl_1\") # add left vslot to bottom-left connector\n", "door.assemble(\"right_0\", \"con_br_0\") # add right vslot to bottom-right connector\n", "door.assemble(\"panel_0\", \"panel_1\") # add panel\n", "door.assemble(\"con_tl_0\", \"left_0\") # add top-left connector to left vslot\n", "door.assemble(\"con_tr_1\", \"right_1\") # add top-right connector to right vslot\n", "door.assemble(\"top_1\", \"con_tl_1\") # add top vslot to top-left connector\n", "door.assemble(\"handle_0\", \"handle_1\") # add handle\n", "\n", "show(door, render_mates=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# The Solver based tutorial" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cv2 = open_viewer(\"Door2\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import cadquery as cq\n", "\n", "# Parameters\n", "H = 400\n", "W = 200\n", "D = 350\n", "\n", "PROFILE = cq.importers.importDXF(\"./vslot-2020_1.dxf\").wires()\n", "\n", "SLOT_D = 6\n", "PANEL_T = 3\n", "\n", "HANDLE_D = 20\n", "HANDLE_L = 50\n", "HANDLE_W = 4\n", "\n", "\n", "def make_vslot(l):\n", "\n", " return PROFILE.toPending().extrude(l)\n", "\n", "\n", "def make_connector():\n", "\n", " rv = (\n", " cq.Workplane()\n", " .box(20, 20, 20)\n", " .faces(\"X\").tag(\"X\").end()\n", " rv.faces(\">Z\").tag(\"Z\").end()\n", "\n", " return rv\n", "\n", "\n", "def make_panel(w, h, t, cutout):\n", "\n", " rv = (\n", " cq.Workplane(\"XZ\")\n", " .rect(w, h)\n", " .extrude(t)\n", " .faces(\">Y\")\n", " .vertices()\n", " .rect(2*cutout,2*cutout)\n", " .cutThruAll()\n", " .faces(\"Y\").edges(\"%CIRCLE\").edges(\">Z\").tag(\"hole1\")\n", " rv.faces(\">Y\").edges(\"%CIRCLE\").edges(\"Y\").tag(\"mate1\")\n", " rv.faces(\"Z\", \"con_tl?Z\", \"Plane\")\n", " .constrain(\"left@faces@Y\", \"Axis\")\n", " # bottom\n", " .constrain(\"bottom@faces@Y\", \"Axis\")\n", " .constrain(\"bottom@faces@>Z\", \"con_bl?X\", \"Plane\")\n", " # right connectors\n", " .constrain(\"top@faces@>Z\", \"con_tr@faces@>X\", \"Plane\")\n", " .constrain(\"bottom@faces@X\", \"Plane\")\n", " .constrain(\"left@faces@>Z\", \"con_tr?Z\", \"Axis\")\n", " .constrain(\"left@faces@Z\", \"con_tr@faces@>Z\", \"Plane\")\n", " .constrain(\"right@faces@X[-4]\", \"panel@faces@Z\", \"panel@faces@>Z\", \"Axis\")\n", " # handle\n", " .constrain(\"panel?hole1\", \"handle?mate1\", \"Plane\")\n", " .constrain(\"panel?hole2\", \"handle?mate2\", \"Point\")\n", ")\n", "\n", "# solve\n", "door.solve()\n", "\n", "show_object(door,name='door')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 4 }