jupyter-replicad
v1.0.0
Published
A JupyterLab extension for rendering replicad shapes in Jupyter notebook output cells.
Maintainers
Readme
Jupyter Replicad
A JupyterLab extension for rendering replicad shapes in Jupyter notebook output cells. Also behaves as a notebook renderer in Visual Studio Code.
Installation
For VS Code
I haven't gotten around to actually publishing this and dealing with Microsoft's requirements yet, but feel free to grab the .vsix file from the Pipeline artifacts and install it yourself by going to VS Code > Extensions > 3 dot menu at top right of extensions list > Install from VSIX... and selecting the file.
For JupyterLab
Not how I use it so haven't really prioritized this.
You can download the .whl from the Pipeline artifacts and install it with the following command:
pip install "jupyterlab>=4.0.0,<5" dist/jupyter_replicad*.whlChange
dist/jupyter_replicad*.whlto the path of the file as you downloaded it.
Usage
To start, initialize the environment and associate replicad with OpenCascade:
import * as replicad from "npm:replicad";
import display, { initializeEnvironment } from "jupyter-replicad/display";
await initializeEnvironment(replicad);The idea is that you pass it the reference to the current context's version of replicad and it will use that for serialization. This is required to determine which type of shapes you are displaying.
As you build your replicad shapes, you can display them as cell outputs:
import type { MaterialConfiguration } from "jupyter-replicad/display";
const shape = replicad.makeSphere(10);
const material: MaterialConfiguration = {
color: "#FF0000",
opacity: 0.75,
roughness: 0,
metalness: 0.1
};
await Deno.jupyter.display(
display([
{
name: "My Red Sphere",
shape,
material
}
]),
{ raw: true }
);
// Alternative syntax:
await Deno.jupyter.display({
[Symbol.for("Jupyter.display")]() {
return display([
{
name: "My Red Sphere",
shape,
material
}
])
}
});Under the hood, this serializes the shapes to JSON with the MIME type "application/replicad-json".
Future Plans
Feel free to reach out if any of these would be particularly useful for you! I'm always happy to collaborate and hear how you're using the tool.
- Support for 2D output (
Drawings,Blueprints, etc.) - Displaying non-solid shapes (
Surfaces,Shells, etc.) - Integration with tscircuit
- Better documentation
- Publishing extension from CI
- Utilities for exporting shapes and nicely displaying the result
Development
I'm documenting this for my own sanity.
npm run build:lib-main
npm run build:lib-display
npm run build:lib-vscode
npm run build:vscode-extension