{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "11d86549-d553-4483-be2d-24ec757d2630", "metadata": {}, "outputs": [], "source": [ "from jupyter_cadquery import show, open_viewer, set_defaults\n", "from build123d import *\n", "\n", "cv = open_viewer(\"Build123d\", cad_width=780, glass=True)\n", "\n", "set_defaults(edge_accuracy=0.0001)" ] }, { "cell_type": "code", "execution_count": null, "id": "abe2d029-0b01-46ca-aa08-eb22221fbd16", "metadata": {}, "outputs": [], "source": [ "with BuildPart() as b:\n", " Box(1, 1, 1)\n", " CounterBoreHole(0.2, 0.3, 0.1)\n", " Box(1, 0.2, 1, mode=Mode.SUBTRACT)\n", " Box(0.2, 1, 1, mode=Mode.SUBTRACT)\n", "\n", "with BuildSketch() as s:\n", " with BuildLine() as line:\n", " l = Line((0, 0), (1, 0))\n", " Line(l @ 1, (1, 1))\n", " offset(line.line.edges(), amount=1)\n", " make_face()\n", "\n", "with BuildLine() as l:\n", " l1 = Polyline((0.0000, 0.0771), (0.0187, 0.0771), (0.0094, 0.2569))\n", " l2 = Polyline((0.0325, 0.2773), (0.2115, 0.2458), (0.1873, 0.3125))\n", " RadiusArc(l1 @ 1, l2 @ 0, 0.0271)\n", " l3 = Polyline((0.1915, 0.3277), (0.3875, 0.4865), (0.3433, 0.5071))\n", " TangentArc(l2 @ 1, l3 @ 0, tangent=l2 % 1)\n", " l4 = Polyline((0.3362, 0.5235), (0.375, 0.6427), (0.2621, 0.6188))\n", " SagittaArc(l3 @ 1, l4 @ 0, 0.003)\n", " l5 = Polyline((0.2469, 0.6267), (0.225, 0.6781), (0.1369, 0.5835))\n", " ThreePointArc(l4 @ 1, (l4 @ 1 + l5 @ 0) * 0.5 + Vector(-0.002, -0.002), l5 @ 0)\n", " l6 = Polyline((0.1138, 0.5954), (0.1562, 0.8146), (0.0881, 0.7752))\n", " Spline(l5 @ 1, l6 @ 0, tangents=(l5 % 1, l6 % 0), tangent_scalars=(2, 2))\n", " l7 = Line((0.0692, 0.7808), (0.0000, 0.9167))\n", " TangentArc(l6 @ 1, l7 @ 0, tangent=l6 % 1)\n", " mirror(l.edges(), about=Plane.YZ)\n" ] }, { "cell_type": "markdown", "id": "e97cf194-caf2-4549-9607-c985e1fcc9e1", "metadata": {}, "source": [ "## BuildPart, BuildSketch, BuildLine" ] }, { "cell_type": "code", "execution_count": null, "id": "968f720a-2e00-414d-9404-f7ac6516bd3b", "metadata": {}, "outputs": [], "source": [ "show(b)" ] }, { "cell_type": "code", "execution_count": null, "id": "a2568530-bd57-4364-baae-d16e49ff69fc", "metadata": {}, "outputs": [], "source": [ "show(s)" ] }, { "cell_type": "code", "execution_count": null, "id": "c8a9da63-e685-4c43-9989-b8fcde637535", "metadata": {}, "outputs": [], "source": [ "show(l)" ] }, { "cell_type": "markdown", "id": "5696f436-1d19-42fe-af89-ccefc397d325", "metadata": {}, "source": [ "## BuildPart.part, BuildSketch.sketch, BuildLine.line" ] }, { "cell_type": "code", "execution_count": null, "id": "c79c3236-f8a6-4819-b01b-5de97ec2bf93", "metadata": {}, "outputs": [], "source": [ "show(b.part)" ] }, { "cell_type": "code", "execution_count": null, "id": "8e2d9e05-e924-46cf-b24a-e0dfc162000b", "metadata": {}, "outputs": [], "source": [ "show(s.sketch)" ] }, { "cell_type": "code", "execution_count": null, "id": "85226f6b-331a-4cbf-a84c-a816a19b255a", "metadata": {}, "outputs": [], "source": [ "show(l.line)" ] }, { "cell_type": "markdown", "id": "c3011fd1-f339-4c50-8e34-7cbc7a2d4093", "metadata": {}, "source": [ "## BuildPart.part.wrapped, BuildSketch.sketch.wrapped, BuildLine.line.wrapped" ] }, { "cell_type": "code", "execution_count": null, "id": "231d821f-4fa4-4fc2-bfba-6d466dca5ae9", "metadata": {}, "outputs": [], "source": [ "show(b.part.wrapped)" ] }, { "cell_type": "code", "execution_count": null, "id": "7d7ca0b5-3e42-4d4f-83b0-05353e4b8940", "metadata": {}, "outputs": [], "source": [ "show(s.sketch.wrapped)" ] }, { "cell_type": "code", "execution_count": null, "id": "3bc418d9-99d5-4c5e-bf56-f122b8d6a502", "metadata": {}, "outputs": [], "source": [ "show(l.line.wrapped)" ] }, { "cell_type": "markdown", "id": "453c177d-659d-4440-9ddb-07b8ed06ed0f", "metadata": {}, "source": [ "## ShapeLists" ] }, { "cell_type": "code", "execution_count": null, "id": "605786fc-e1b6-4abe-859b-6942968c1857", "metadata": {}, "outputs": [], "source": [ "show(b.solids()[0:2])" ] }, { "cell_type": "code", "execution_count": null, "id": "7b72766c-2ec7-42fc-bbb5-f1485d237795", "metadata": {}, "outputs": [], "source": [ "show(b, b.faces()[0:2], transparent=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "b9c46806-c793-4292-9405-a99c00e2cdbc", "metadata": {}, "outputs": [], "source": [ "show(b, b.wires()[0:2], transparent=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "ad7fca69-e566-4cc6-beee-f2cba8c2ff58", "metadata": {}, "outputs": [], "source": [ "show(b, b.edges()[0:2], transparent=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "09ebb2f9-5c59-4fb6-ba47-6b04a026a6e2", "metadata": {}, "outputs": [], "source": [ "show(b, b.vertices()[0:2], transparent=True)" ] }, { "cell_type": "markdown", "id": "2333e981-8542-4717-9e1a-2b7c3c5ac1e3", "metadata": {}, "source": [ "## Direct API" ] }, { "cell_type": "code", "execution_count": null, "id": "ae1b5db7-52a8-4f8f-8081-42a7e5f77569", "metadata": {}, "outputs": [], "source": [ "show(b.solids().sort_by(Axis.X)[-1])" ] }, { "cell_type": "code", "execution_count": null, "id": "e0389b26-73b4-42e4-9a9d-5b9f60ac7c06", "metadata": {}, "outputs": [], "source": [ "show(b, b.faces().sort_by(Axis.Z)[-1], transparent=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "a3569ef9-6ce2-4fbd-a80b-146d5021617f", "metadata": {}, "outputs": [], "source": [ "show(b, b.wires().sort_by(Axis.Z)[-1], transparent=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "25a94934-f007-4e8f-adf6-0ef6a43a0a48", "metadata": {}, "outputs": [], "source": [ "show(b, b.edges().sort_by(Axis.Z)[-1], transparent=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "0b556940-5bfd-4341-ad4a-9ab33f4ceabd", "metadata": {}, "outputs": [], "source": [ "show(b, b.vertices().sort_by(Axis.Z)[-1], transparent=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "8ea8ac91-745b-4e74-8e45-2b1cd99d0e3c", "metadata": {}, "outputs": [], "source": [ "show(b.solids().sort_by(Axis.X)[-1].wrapped)" ] }, { "cell_type": "code", "execution_count": null, "id": "3c59d354-fbf9-4ad0-944a-1c2619f9fbdf", "metadata": {}, "outputs": [], "source": [ "show(b, b.faces().sort_by(Axis.Z)[-1].wrapped, transparent=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "5264c499-df8c-4a4f-a01d-0209249541a4", "metadata": {}, "outputs": [], "source": [ "show(b, b.wires().sort_by(Axis.Z)[-1].wrapped, transparent=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "d7a77e19-73de-4008-aeb7-4fdb667c7dc7", "metadata": {}, "outputs": [], "source": [ "show(b, b.edges().sort_by(Axis.Z)[-1].wrapped, transparent=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "8d06bbea-655c-4e3d-9b8a-89b74252da84", "metadata": {}, "outputs": [], "source": [ "show(b, b.vertices().sort_by(Axis.Z)[-1].wrapped, transparent=True)" ] }, { "cell_type": "markdown", "id": "e0ff1d59-0aa5-4c4f-a776-7b207cc20101", "metadata": {}, "source": [ "## Tutorial" ] }, { "cell_type": "markdown", "id": "131f03b6-536e-449e-a9d8-30ab94b99161", "metadata": {}, "source": [ "### Tutorial 1" ] }, { "cell_type": "code", "execution_count": null, "id": "15f76e5a-8ea2-452d-bdd8-594e456a4786", "metadata": {}, "outputs": [], "source": [ "with BuildPart() as example:\n", " Cylinder(radius=10, height=3)\n", " with BuildSketch(example.faces().sort_by()[-1]):\n", " RegularPolygon(radius=7, side_count=6)\n", " Circle(radius=4, mode=Mode.SUBTRACT)\n", " extrude(amount=-2, mode=Mode.SUBTRACT)\n", " fillet(\n", " example\n", " .edges()\n", " .filter_by(GeomType.CIRCLE)\n", " .sort_by(SortBy.RADIUS)[-2:]\n", " .sort_by(Axis.Z), \n", " radius=1\n", " )\n", "show(example)" ] }, { "cell_type": "markdown", "id": "d2ee056e-264d-4ecf-b75a-aee23aec5016", "metadata": {}, "source": [ "### Tutorial 2" ] }, { "cell_type": "code", "execution_count": null, "id": "46b35391-9f26-4f20-a787-b5eaf3b4c017", "metadata": {}, "outputs": [], "source": [ "pip_count = 6\n", "\n", "lego_unit_size = 8\n", "pip_height = 1.8\n", "pip_diameter = 4.8\n", "block_length = lego_unit_size * pip_count\n", "block_width = 16\n", "base_height = 9.6\n", "block_height = base_height + pip_height\n", "support_outer_diameter = 6.5\n", "support_inner_diameter = 4.8\n", "ridge_width = 0.6\n", "ridge_depth = 0.3\n", "wall_thickness = 1.2" ] }, { "cell_type": "code", "execution_count": null, "id": "55ca47f2-ec5a-4e7c-b646-9cb50f0671d8", "metadata": {}, "outputs": [], "source": [ "with BuildPart() as lego:\n", " with BuildSketch():\n", " perimeter = Rectangle(block_length, block_width)\n", " offset(\n", " perimeter,\n", " amount=-wall_thickness,\n", " kind=Kind.INTERSECTION,\n", " mode=Mode.SUBTRACT,\n", " )\n", " with GridLocations(0, lego_unit_size, 1, 2):\n", " Rectangle(block_length, ridge_width)\n", " with GridLocations(lego_unit_size, 0, pip_count, 1):\n", " Rectangle(ridge_width, block_width)\n", " Rectangle(\n", " block_length - 2 * (wall_thickness + ridge_depth),\n", " block_width - 2 * (wall_thickness + ridge_depth),\n", " mode=Mode.SUBTRACT,\n", " )\n", " with GridLocations(lego_unit_size, 0, pip_count - 1, 1):\n", " Circle(support_outer_diameter / 2)\n", " Circle(support_inner_diameter / 2, mode=Mode.SUBTRACT)\n", " extrude(amount=base_height - wall_thickness)\n", " with Locations(\n", " Plane(origin=(0, 0, lego.vertices().sort_by(Axis.Z)[-1].Z), z_dir=(0, 0, 1)).location\n", " ):\n", " Box(\n", " block_length,\n", " block_width,\n", " wall_thickness,\n", " align=(Align.CENTER, Align.CENTER, Align.MIN),\n", " )\n", " with Locations(lego.faces().sort_by(Axis.Z)[-1]):\n", " with GridLocations(lego_unit_size, lego_unit_size, pip_count, 2):\n", " Cylinder(\n", " radius=pip_diameter / 2, height=pip_height, align=(Align.CENTER, Align.CENTER, Align.MIN)\n", " )\n" ] }, { "cell_type": "code", "execution_count": null, "id": "ef340ca8-ece8-491d-8dfd-8c806704678d", "metadata": {}, "outputs": [], "source": [ "show(lego)" ] }, { "cell_type": "code", "execution_count": null, "id": "98ef16b2-22fa-458e-8f0c-8451e1eef82a", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }