codeCAD/dempf.ipynb
2026-02-27 02:05:50 +01:00

334 lines
9.6 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "f4f3de42-6096-4701-98ff-6b5034dfcc97",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting auto display for cadquery Workplane and Shape\n"
]
}
],
"source": [
"import timeit\n",
"tic = timeit.default_timer()\n",
"\n",
"import cadquery as cq\n",
"from math import sin, cos, pi\n",
"\n",
"\n",
"\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",
"\n",
"from jupyter_cadquery.replay import replay, enable_replay, disable_replay\n",
"''\n",
"\n",
"from build123d import *"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "be6cd832-8790-46db-aea3-e8b44b8609ca",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'viewer': 'dempf',\n",
" 'anchor': 'right',\n",
" 'cad_width': 600,\n",
" 'tree_width': 250,\n",
" 'height': 600,\n",
" 'theme': 'light',\n",
" 'pinning': False,\n",
" 'angular_tolerance': 0.2,\n",
" 'deviation': 0.1,\n",
" 'edge_accuracy': None,\n",
" 'default_color': (232, 176, 36),\n",
" 'default_edge_color': '#707070',\n",
" 'optimal_bb': False,\n",
" 'render_normals': False,\n",
" 'render_edges': True,\n",
" 'render_mates': False,\n",
" 'parallel': False,\n",
" 'mate_scale': 1,\n",
" 'control': 'trackball',\n",
" 'up': 'Z',\n",
" 'axes': False,\n",
" 'axes0': False,\n",
" 'grid': [False, False, False],\n",
" 'ticks': 10,\n",
" 'ortho': True,\n",
" 'transparent': False,\n",
" 'black_edges': False,\n",
" 'ambient_intensity': 0.75,\n",
" 'direct_intensity': 0.15,\n",
" 'reset_camera': True,\n",
" 'show_parent': True,\n",
" 'show_bbox': False,\n",
" 'position': None,\n",
" 'quaternion': None,\n",
" 'target': None,\n",
" 'zoom': None,\n",
" 'zoom_speed': 1.0,\n",
" 'pan_speed': 1.0,\n",
" 'rotate_speed': 1.0,\n",
" 'collapse': 1,\n",
" 'tools': True,\n",
" 'glass': True,\n",
" 'timeit': False,\n",
" 'js_debug': False}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"close_viewers()\n",
"\n",
"set_defaults(viewer=\"dempf\",\n",
" cad_width=600, \n",
" #height=480,\n",
" )\n",
"\n",
"\n",
"cv = open_viewer(\"dempf\",\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",
"#enable_replay(False, False)\n",
"#show_object = replay\n",
"\n",
"get_defaults()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "fad67912-407f-4263-a496-287ea7160753",
"metadata": {},
"outputs": [],
"source": [
"def seal_metal_pipe():\n",
" pipe = (cq.Workplane(\"XY\")\n",
" .sketch()\n",
" .circle(20, mode=\"c\", tag=\"circ\") \n",
" .select(\"circ\")\n",
" .wires()\n",
" .distribute(8)\n",
" .rect(2,2)\n",
" .finalize()\n",
" .extrude(2)\n",
" )\n",
" return pipe\n",
"\n",
"#.circle(15)\n",
"## .circle(14)\n",
"# .extrude(60)\n",
"# .faces(\">Z\")\n",
"\n",
"pipe = seal_metal_pipe()\n",
"pipe"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "d6ed6a98-1cc6-489a-8b65-e5d99837d8da",
"metadata": {},
"outputs": [],
"source": [
"cv1 = show(pipe)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "495f885e-5b92-4453-8c96-5c532fd7d46a",
"metadata": {},
"outputs": [],
"source": [
"pipe"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "14a5ae42-0246-4999-9818-0df5e5c0bfc7",
"metadata": {},
"outputs": [],
"source": [
"from cadquery.selectors import AreaNthSelector\n",
"\n",
"result = (\n",
" cq.Workplane(\"XY\")\n",
" .rect(20, 20)\n",
" .extrude(10)\n",
" .edges(\"|Z or <Z\")\n",
" .fillet(2)\n",
" .faces(\">Z\")\n",
" .shell(2)\n",
" .faces(\">Z\")\n",
" .wires(AreaNthSelector(-1))\n",
" .toPending()\n",
" .workplane()\n",
" .offset2D(-1)\n",
" .extrude(1)\n",
" .faces(\">Z[-2]\")\n",
" .wires(AreaNthSelector(0))\n",
" .toPending()\n",
" .workplane()\n",
" .cutBlind(2)\n",
")\n",
"result"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "10ef4488-c40a-4dc2-a723-2061632b8529",
"metadata": {},
"outputs": [],
"source": [
"with BuildPart() as p:\n",
" with BuildSketch() as pipe:\n",
" Circle(20)\n",
" Circle(19, mode=Mode.SUBTRACT)\n",
" extrude(amount=20)\n",
" with BuildSketch() as s:\n",
" with PolarLocations(20,8):\n",
" Rectangle(5,2)\n",
" extrude(amount=2, mode=Mode.SUBTRACT)\n",
" \n",
"p"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "027849ae-2b65-4473-8c5e-744691b85c2e",
"metadata": {},
"outputs": [],
"source": [
"\n",
"pipe = (cq.Workplane(\"XY\")\n",
" .sketch()\n",
" .circle(20)\n",
" .circle(19, mode=\"s\")\n",
" .finalize()\n",
" .extrude(40, both=False)\n",
" )\n",
" \n",
"holes = (pipe.faces(\">Z\")\n",
" .sketch()\n",
" .circle(20, mode=\"c\", tag=\"circ\") \n",
" .select(\"circ\")\n",
" .wires()\n",
" .distribute(8)\n",
" .rect(3,2)\n",
" .finalize()\n",
" .extrude(-2, combine=\"s\")\n",
" .faces(\"<Z\")\n",
" .sketch()\n",
" .circle(20, mode=\"c\", tag=\"circ\") \n",
" .select(\"circ\")\n",
" .wires()\n",
" .distribute(8)\n",
" .rect(3,2)\n",
" .finalize()\n",
" .extrude(2, combine=\"s\")\n",
" )\n",
"holes"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "d793cdb0-ef0b-465d-9dbb-6d1115de1320",
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "Workplane.polyline() missing 1 required positional argument: 'listOfXYTuple'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[9], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m yoghurt_extender \u001b[38;5;241m=\u001b[39m(\u001b[43mcq\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mWorkplane\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mXZ\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m----> 2\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpolyline\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;241m.\u001b[39msketch()\n\u001b[1;32m 4\u001b[0m \n\u001b[1;32m 5\u001b[0m \u001b[38;5;241m.\u001b[39mrect(\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m100\u001b[39m)\n\u001b[1;32m 6\u001b[0m \u001b[38;5;241m.\u001b[39mrect(\u001b[38;5;241m1.5\u001b[39m,\u001b[38;5;241m4\u001b[39m)\n\u001b[1;32m 7\u001b[0m \n\u001b[1;32m 8\u001b[0m )\n\u001b[1;32m 9\u001b[0m yoghurt_extender \n",
"\u001b[0;31mTypeError\u001b[0m: Workplane.polyline() missing 1 required positional argument: 'listOfXYTuple'"
]
}
],
"source": [
"yoghurt_extender =(cq.Workplane(\"XZ\")\n",
" .polyline()\n",
" .sketch()\n",
" \n",
" .rect(2,100)\n",
" .rect(1.5,4)\n",
" \n",
" )\n",
"yoghurt_extender "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "51ec37d0-ea15-433a-9aad-16e05837e93b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "c4ea0f7f-9ac1-4ff0-9740-787a17cba1bc",
"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
}