Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/sdf.egg-info
*.stl

__pycache__/
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"ms-python.python",
"ms-toolsai.jupyter"
]
}
Binary file added docs/images/vscad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# install this folder
.
# requirements for visualization
ipykernel
ipywidgets
pyvista
trame
trame-vtk
trame-vuetify
113 changes: 113 additions & 0 deletions vscad.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "20cf6981",
"metadata": {},
"outputs": [],
"source": [
"# imports\n",
"from sdf import *\n",
"import pyvista as pv"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "7adef045",
"metadata": {},
"outputs": [],
"source": [
"# create shape\n",
"\n",
"f = sphere(1) & box(1.5)\n",
"\n",
"c = cylinder(0.5)\n",
"f -= c.orient(X) | c.orient(Y) | c.orient(Z)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "5b8032f5",
"metadata": {},
"outputs": [],
"source": [
"# display and output variables\n",
"window_size = [1600, 900]\n",
"stl_samples = 2**26\n",
"file_name = \"object.stl\"\n",
"\n",
"# create plotter\n",
"pv.global_theme = pv.themes.DarkTheme()\n",
"plotter = pv.Plotter(window_size=window_size)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a4768d1f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"min -0.84543, -0.84543, -0.84543\n",
"max 0.845431, 0.845431, 0.845431\n",
"step 0.00416084, 0.00416084, 0.00416084\n",
"73560059 samples in 2197 batches with 16 workers\n",
" 100% (2197 of 2197) [##############################] 0:00:05 0:00:00 \n",
"1010 skipped, 379 empty, 808 nonempty\n",
"1852312 triangles in 4.73984 seconds\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "15191bf28d9a4f309afe82a3d70e809d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Widget(value='<iframe src=\"http://localhost:48781/index.html?ui=P_0x24362167c50_1&reconnect=auto\" class=\"pyvis…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# save to stl\n",
"f.save(file_name, samples=stl_samples)\n",
"\n",
"# read and display stl\n",
"mesh = pv.read(file_name)\n",
"plotter.add_mesh(mesh, color=\"lightblue\")\n",
"plotter.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"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.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
22 changes: 22 additions & 0 deletions vscad.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Visual Studio CAD

It is possible to use Visual Studio Code as a primitive CAD program, where you can quickly iterate on an STL and visualize it in 3D right in the editor.

## Setup

1. (Recommended) create a virtual environment using the virtual environment manager of your choice
- `python3 -m venv .venv`
2. Install the required python packages
- `pip install -r requirements.txt`
3. Install the required Visual Studio Code Extensions found in `.vscode/extensions.json`
4. Open [`vscad.ipynb`](./vscad.ipynb)
5. Select the appropriate python environment as your kernel
6. Run the file!

## Recommendations

- Turn the samples down a few orders of magnitude when prototyping to go faster, then back up for the final output
- Resize the pv output window to something suitable for your monitor
- Make sure to move the file or change the name when you're done with a part so you don't overwrite it when you go to start the next one!

![rendered STL in VSCode](docs/images/vscad.png)