{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "a0dc6484-8b39-4f43-a765-11e567de1746", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Overwriting auto display for cadquery Workplane and Shape\n", "import runtime: 2.6s\n" ] } ], "source": [ "import timeit\n", "\n", "tictime = 0\n", "def tic():\n", " global tictime\n", " tictime = timeit.default_timer()\n", "\n", "def toclog(custom_msg=None):\n", " toc = timeit.default_timer()\n", " runtime = toc - tictime\n", " msg = \"runtime\" if not custom_msg else custom_msg\n", " print(f\"{msg}: {runtime:2.2}s\")\n", " \n", "tic()\n", "\n", "\n", "\n", "from build123d import *\n", "from jupyter_cadquery import (\n", " versions,\n", " show, PartGroup, Part, \n", " get_viewer, close_viewer, get_viewers, close_viewers, open_viewer, set_defaults, get_defaults, open_viewer,\n", " get_pick,\n", ")\n", "from jupyter_cadquery.ocp_utils import webcol_to_cq\n", "\n", "from jupyter_cadquery.replay import replay, enable_replay, disable_replay\n", "\n", "toclog(\"import runtime\")" ] }, { "cell_type": "code", "execution_count": 2, "id": "6b46efca-c212-4c0d-9e39-a6d82d51bbec", "metadata": {}, "outputs": [], "source": [ "cv = open_viewer(\"REGAL\",\n", " anchor=\"right\", \n", " glass=True, \n", " tools=False) # sets default viewer\n", "\n", "\n", "cv.grid = [not g for g in cv.widget.grid]\n", "\n", "cv.axes = not cv.axes\n", "cv.axes0 = not cv.axes0\n", "cv.transparent = not cv.transparent\n", "cv.black_edges = not cv.black_edges\n", "\n", "set_defaults(\n", " cad_width=640, \n", " height=480, \n", " viewer=\"REGAL\"\n", ")" ] }, { "cell_type": "code", "execution_count": 20, "id": "44dd6c5a-c307-4284-8074-ec9086df4239", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[32;1m\n", "*******************************************************************\n", "****** Statistics on Transfer (Write) ******\u001b[0m\n", "\u001b[32;1m\n", "*******************************************************************\n", "****** Transfer Mode = 0 I.E. As Is ******\u001b[0m\n", "\u001b[32;1m****** Transferring Shape, ShapeType = 0 ******\u001b[0m\n", "\u001b[32;1m** WorkSession : Sending all data\u001b[0m\n", "\u001b[32;1m Step File Name : regal_5x5.step(15716 ents) Write Done\u001b[0m\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/tmp/ipykernel_223/3924664858.py:37: DeprecationWarning: Use the `export_step` function instead\n", " regal.export_step(f'regal_{n_hor_boards}x{n_vert_boards}.step')\n" ] }, { "data": { "text/plain": [ "" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from build123d import *\n", "\n", "h = 200\n", "w = 200\n", "d = 80\n", "t = 3\n", "n_vert_boards = 5\n", "n_hor_boards = 5\n", "dw = (w-t)/(n_vert_boards-1)\n", "dh = (h-t)/(n_hor_boards-1)\n", "tol = 1\n", "\n", "\n", "with BuildPart() as cutouts:\n", " with BuildSketch(Plane.XZ.offset(d/2)) as sk:\n", " with Locations(*tuple((j*dw-tol,dh*i-tol) \\\n", " for i in range(n_hor_boards) \\\n", " for j in range(n_vert_boards))):\n", " Rectangle(t+tol*2,t+tol*2, align=Align.MIN)\n", " extrude(amount=d/2+tol)\n", "\n", "with BuildPart() as vboards:\n", " with BuildSketch(Plane.XZ) as sk:\n", " with Locations(*tuple((dw*i, 0.0) for i in range(n_vert_boards))):\n", " Rectangle(t, h, align=Align.MIN)\n", " extrude(amount=d)\n", " add(cutouts.part, mode=Mode.SUBTRACT)\n", " \n", "with BuildPart() as hboards: \n", " with BuildSketch(Plane.XZ.offset(d/2)) as sk:\n", " with Locations(*tuple((0.0,dh*i) for i in range(n_hor_boards))):\n", " Rectangle(w,t, align=Align.MIN)\n", " extrude(amount=d)\n", " add(cutouts.part, mode=Mode.SUBTRACT)\n", "\n", "\n", "hboards = hboards.part.translate((0,d/2,0))\n", "\n", "regal = Compound(label=\"regal\", children=(vboards.part, hboards))\n", "\n", "regal.export_step(f'regal_{n_hor_boards}x{n_vert_boards}.step')" ] }, { "cell_type": "code", "execution_count": 11, "id": "ee75ab94-20d0-421e-a30b-06c4ae888206", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "100% ⋮————————————————————————————————————————————————————————————⋮ (2/2) 0.09s\n" ] } ], "source": [ "packed = pack((vertboards.part, horboards),\\\n", " padding=5, align_z=False)\n", "Compound(packed)" ] }, { "cell_type": "code", "execution_count": 16, "id": "7e29334c-787c-474b-aab5-e92b72e93c66", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Versions:\n", "- jupyter_cadquery 3.5.2\n", "- cad_viewer_widget 1.4.1\n", "- open cascade 7.6.3\n", "\n", "Plugins loaded:\n", "- build123d\n", "- cadquery-massembly\n" ] } ], "source": [ "versions()" ] }, { "cell_type": "code", "execution_count": 18, "id": "e80b28dd-4739-4d79-a47e-d5c17e6fb3e9", "metadata": {}, "outputs": [], "source": [ "with BuildPart() as cupbuilder:\n", " with BuildSketch() as sk:\n", " Circle(30)\n", " extrude(amount=60)\n", " with Locations((30, 0, 10), (30, 0, 45)):\n", " b = Box(15, 40, 10)\n", " #b.edges().sort_by(b.edges(),Axis.is_parallel(Axis.Z))\n", " with BuildSketch(cupbuilder.faces().sort_by(Axis.Z)[-1]) as sk1:\n", " Circle(25)\n", " extrude(amount=-55, mode=Mode.SUBTRACT)\n", " #offset(amount=-6, openings=f)\n", " fillet(cupbuilder.edges().sort_by(Axis.Z)[-2], radius=3)\n", " with Locations((32,0,30)):\n", " Box(4, 30, 60, mode=Mode.SUBTRACT)\n", " with Locations((36,0,30)): \n", " Box(8, 4, 60, mode=Mode.SUBTRACT)\n", "cupbuilder" ] }, { "cell_type": "code", "execution_count": 20, "id": "2551e7ff-dde4-40a6-9ad6-63cd513a5ea7", "metadata": {}, "outputs": [], "source": [ "b.edges().pa" ] }, { "cell_type": "code", "execution_count": 15, "id": "d7bbd569-8c84-4d3a-8466-ac1fa95ff480", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0.6.1.dev11+g31c2aaa'" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from build123d import __version__\n", "__version__" ] }, { "cell_type": "code", "execution_count": 32, "id": "e7ec04b2-3b3d-4f66-9374-b8dbe9445c72", "metadata": {}, "outputs": [], "source": [ "sheet_thickness = 4 * MM\n", "\n", "with BuildPart() as side:\n", " d = Vector(1, 0, 0).rotate(Axis.Y, 60)\n", " with BuildLine(Plane.XZ) as side_line:\n", " l1 = Line((0, 65), (170 / 2, 65))\n", " l2 = PolarLine(l1 @ 1, length=65, direction=d, length_mode=LengthMode.VERTICAL)\n", " l3 = Line(l2 @ 1, (170 / 2, 0))\n", " fillet(side_line.vertices(), 7)\n", " make_brake_formed(\n", " thickness=sheet_thickness,\n", " station_widths=[40, 40, 40, 112.52 / 2, 112.52 / 2, 112.52 / 2],\n", " side=Side.RIGHT,\n", " )\n", " fe = side.edges().filter_by(Axis.Z).group_by(Axis.Z)[0].sort_by(Axis.Y)[-1]\n", " fillet(fe, radius=7)\n", "side" ] }, { "cell_type": "code", "execution_count": 2, "id": "bc9fe2d7-c65f-481d-93ae-46ad90172418", "metadata": {}, "outputs": [ { "ename": "ImportError", "evalue": "cannot import name '__version__' from 'os' (/opt/conda/envs/cq/lib/python3.10/os.py)", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mos\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m __version__\n", "\u001b[0;31mImportError\u001b[0m: cannot import name '__version__' from 'os' (/opt/conda/envs/cq/lib/python3.10/os.py)" ] } ], "source": [ "import os" ] }, { "cell_type": "code", "execution_count": null, "id": "6c9865a4-0062-4f8b-9f57-48170042bcee", "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.10.8" } }, "nbformat": 4, "nbformat_minor": 5 }