Skip to main content

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 jupyterscad

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.5,2,1],center=True)

OpenSCAD

obj = 'cube([1.5,2,1],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.

render example

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 2019 (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

jupyterscad-0.1.1.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

jupyterscad-0.1.1-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file jupyterscad-0.1.1.tar.gz.

File metadata

  • Download URL: jupyterscad-0.1.1.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for jupyterscad-0.1.1.tar.gz
Algorithm Hash digest
SHA256 010b7fd441aecc58cf1ed30f4a08aa77aca67155ec801a31ec8fb1f17ef2b336
MD5 319931ab808bdc6b4d083937f4f23abc
BLAKE2b-256 3f19fe7ce4a7cb0a589fcdf63405388e73e37b7b9b9dfce296785eb6de2a1b5c

See more details on using hashes here.

File details

Details for the file jupyterscad-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: jupyterscad-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for jupyterscad-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0d5413fa9d5a5c65f79fb7e7e573c85cf82b0f6e90ecaf5899bed254f3c7ddec
MD5 bf18b846314f6b254161239dd42038a2
BLAKE2b-256 3d813ca4ce3788ec046bfb847e8301475943e9f1ccc9df07dedc268a966273e8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page