Solid 3D Cad (SCAD) renderer and viewer for Jupyter
Project description
Jupyter SCAD: SCAD in Jupyter
Jupyter SCAD renders and interactively visualizes 3D objects described in SolidPython2 within a Jupyter notebook.
This program is focused on the use case of generating stl files with Python interactively within a Jupyter notebook.
SolidPython2 generates OpenSCAD language code from Python code. Jupyter SCAD then uses OpenSCAD to render the OpenSCAD code to a 3D model and provides interactive visualization. As an alternative to SolidPython2, the OpenSCAD code can also be provided directly.
Installation
To simply install the package, use pip:
pip install git+https://github.com/jreiberkyle/jupyterscad.git
Alternatively, use container-jupyterscad to run Jupyter SCAD and a pinned version of SolidPython2 in Jupyter lab in a podman container.
Usage
Define an OpenSCAD object
An OpenSCAD object can be defined using SolidPython2 or OpenSCAD.
SolidPython2
from solid2 import *
obj = cube(1)
OpenSCAD
obj = 'cube([60,20,10],center=true);'
Note: If a 3D object description integrates an external stl file, then the stl must be in the same directory as the notebook running the code.
See the OpenSCAD language and SolidPython2 pages for more information on how to use these tools.
Render an OpenSCAD object
from jupyter_scad import render
render(obj)
where obj
is described in OpenSCAD as described above.
The stl generated in rendering can also be saved by defining 'outfile':
from jupyter_scad import render
render(obj, outfile='obj.stl')
Visualize and then Render a stl
from jupyter_scad import visualize_stl, render_stl
render_stl(obj, 'obj.stl')
visualize_stl('obj.stl')
These separate steps allow for generating an stl from an OpenSCAD object without visualization or visualizing an existing stl.
Alternatives
As an alternative to Jupyter SCAD, one could use a Jupyter notebook as an external editor, using SolidPython2 to update the SCAD file and OpenSCAD to visualize and render the SCAD file. The benefit to this approach is that one can visualize the preview. The drawback is that the two-program workflow can feel distracting. See more on using external editors for OpenSCAD here.
Or, one can use ViewSCAD, which was the motivation for this project. However the last time ViewSCAD was updated was 2015 (checked on 9/21/2023). It only supports SolidPython, not SolidPython2.
Transitioning from ViewSCAD
This package was inspired by ViewSCAD and therefore maintains a very similar interface.
To transition from ViewSCAD, replace
import viewscad
r = viewscad.Renderer()
r.render(obj)
with
import jupyterscad
jupyterscad.render(obj)
Visualization Backend
This package uses pythreejs for visualization.
Alternatives considered, ordered from closest fit to farthest:
- pyvolume: provides mesh visualization and interaction but (as of 2023.09.24) the latest release is alpha and documentation is sparse.
- matplotlib mplot3d: provides mesh visualization and interaction but is slow.
- pyvista: provides stl loading and visualization but visualization does not work in docker image.
Acknowledgements
Thanks to nickc92 for creating ViewSCAD, which is the inspiration for this project.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for jupyterscad-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9f041a5ebe474ede3c296c8f7364c5d9df7518fca1f5e53cad437bbdfebefae |
|
MD5 | ecb8d226cdd7a6723f2317a3654ef818 |
|
BLAKE2b-256 | b9f4482188e60ebec6a191a2779ada526b21f2cfc6b1c2aaad4839931a9fa29f |