{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import cadquery as cq\n\n# These can be modified rather than hardcoding values for each dimension.\ncircle_radius = 3.0 # The outside radius of the plate\nthickness = 0.25 # The thickness of the plate\n\n# Make a plate with two cutouts in it by moving the workplane center point\n# 1. Establishes a workplane that an object can be built on.\n# 1a. Uses the named plane orientation \"front\" to define the workplane, meaning\n# that the positive Z direction is \"up\", and the negative Z direction\n# is \"down\".\n# 1b. The initial workplane center point is the center of the circle, at (0,0).\n# 2. A circle is created at the center of the workplane\n# 2a. Notice that circle() takes a radius and not a diameter\nresult = cq.Workplane(\"front\").circle(circle_radius)\n\n# 3. The work center is movide to (1.5, 0.0) by calling center().\n# 3a. The new center is specified relative to the previous center,not\n# relative to global coordinates.\n# 4. A 0.5mm x 0.5mm 2D square is drawn inside the circle.\n# 4a. The plate has not been extruded yet, only 2D geometry is being created.\nresult = result.center(1.5, 0.0).rect(0.5, 0.5)\n\n# 5. The work center is moved again, this time to (-1.5, 1.5).\n# 6. A 2D circle is created at that new center with a radius of 0.25mm.\nresult = result.center(-1.5, 1.5).circle(0.25)\n\n# 7. All 2D geometry is extruded to the specified thickness of the plate.\n# 7a. The small circle and the square are enclosed in the outer circle of the\n# plate and so it is assumed that we want them to be cut out of the plate.\n# A separate cut operation is not needed.\nresult = result.extrude(thickness)\n\n# Displays the result of this script\nshow_object(result)\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.14" } }, "nbformat": 4, "nbformat_minor": 1 }