ktongue's picture
download
raw
3.56 kB
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "815b47a5-28e5-48d3-bebf-d5443133441c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Error: cadquery not found.\n",
"Run this script inside your cadquery conda environment, for example:\n",
" conda activate cadquery\n",
" python ./cylinder.py --out cylinder.stl\n"
]
},
{
"ename": "SystemExit",
"evalue": "1",
"output_type": "error",
"traceback": [
"An exception has occurred, use %tb to see the full traceback.\n",
"\u001b[31mSystemExit\u001b[39m\u001b[31m:\u001b[39m 1\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/tongue/miniconda/lib/python3.13/site-packages/IPython/core/interactiveshell.py:3709: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.\n",
" warn(\"To exit: use 'exit', 'quit', or Ctrl-D.\", stacklevel=1)\n"
]
}
],
"source": [
"import sys\n",
"try:\n",
" import cadquery as cq\n",
" from cadquery import exporters\n",
"except ModuleNotFoundError:\n",
" print(\"Error: cadquery not found.\")\n",
" print(\"Run this script inside your cadquery conda environment, for example:\")\n",
" print(\" conda activate cadquery\")\n",
" print(\" python ./cylinder.py --out cylinder.stl\")\n",
" sys.exit(1)\n",
"\n",
"\n",
"def draw_cylinder(radius=10, height=20, center=True):\n",
" \"\"\"Create and return a CadQuery cylinder.\n",
"\n",
" - radius: cylinder radius\n",
" - height: cylinder height\n",
" - center: if True, center the cylinder on the XY plane (z spans -height/2..+height/2)\n",
" Returns: a CadQuery Workplane object representing the solid.\n",
" \"\"\"\n",
" cyl = cq.Workplane(\"XY\").circle(radius).extrude(height)\n",
" if center:\n",
" cyl = cyl.translate((0, 0, -height / 2.0))\n",
" return cyl\n",
"\n",
"\n",
"def _main():\n",
" import argparse\n",
"\n",
" p = argparse.ArgumentParser(description=\"Create and export a simple cylinder (STL).\")\n",
" p.add_argument(\"--radius\", \"-r\", type=float, default=10.0, help=\"cylinder radius\")\n",
" p.add_argument(\"--height\", \"-H\", type=float, default=20.0, help=\"cylinder height\")\n",
" p.add_argument(\"--center\", action=\"store_true\", help=\"center cylinder on Z axis\")\n",
" p.add_argument(\"--out\", \"-o\", default=\"cylinder.stl\", help=\"output filename (STL/STEP)\")\n",
" args = p.parse_args()\n",
"\n",
" cyl = draw_cylinder(args.radius, args.height, center=args.center)\n",
" exporters.export(cyl, args.out)\n",
" print(f\"Exported: {args.out}\")\n",
"\n",
"\n",
"if __name__ == \"__main__\":\n",
" _main()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3010f5d2-15bd-4ff1-8d25-6f80427a823f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"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.13.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

Xet Storage Details

Size:
3.56 kB
·
Xet hash:
d79e4a5a51d9baed28e6db94e5e3ca1fa3081a4d20fc59689f6a33ffc738b7fb

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.