Skip to main content

A Python package for 3D visualization of SolidPython2 objects

Project description

SolidView

License: MIT Python 3.8+

SolidView is a Python package that provides seamless 3D visualization of objects created with SolidPython2 in Jupyter notebooks. It leverages OpenSCAD for rendering and JupyterSCAD for interactive visualization.

Features

  • 🎯 Easy Integration: Simple API for viewing SolidPython2 objects
  • 🖥️ Cross-Platform: Automatic OpenSCAD detection on Windows, macOS, and Linux
  • 📱 Interactive Viewing: Powered by JupyterSCAD for smooth 3D interaction
  • 💾 STL Export: Built-in functionality to save objects as STL files
  • 🧹 Smart Cleanup: Automatic temporary file management
  • 🎨 Customizable: Configurable viewer dimensions and rendering options

Installation

Prerequisites

  1. OpenSCAD: Download and install from https://openscad.org/
  2. Python 3.8+: Make sure you have Python 3.8 or higher installed

Install SolidView

pip install solidview

Or install from source:

git clone https://github.com/mr-kam/solidview.git
cd solidview
pip install -e .

Development Installation

For development, install with additional dependencies:

pip install -e ".[dev]"

Quick Start

Basic Usage

from solid2 import *
from solidview import view3d

# Create a simple object
cube_obj = cube([10, 10, 10])
sphere_obj = sphere(8)
combined = cube_obj + translate([15, 0, 0])(sphere_obj)

# View it in Jupyter
view3d(combined)

Using the SolidViewer Class

For more control and better performance with multiple objects:

from solidview import SolidViewer
from solid2 import *

# Create a viewer instance
viewer = SolidViewer()

# Create and view multiple objects
for i in range(3):
    obj = translate([i * 20, 0, 0])(cube([10, 10, 10]))
    viewer.view(obj, width=800, height=600)

# Save an object as STL
viewer.save_stl(combined, "my_object.stl")

Custom OpenSCAD Path

If OpenSCAD is installed in a custom location:

from solidview import SolidViewer

viewer = SolidViewer(openscad_exec="/path/to/your/openscad")
viewer.view(your_object)

API Reference

view3d(obj, width=600, height=600, openscad_exec=None)

Convenience function for quick 3D visualization.

Parameters:

  • obj: SolidPython2 object to render
  • width (int): Viewer width in pixels (default: 600)
  • height (int): Viewer height in pixels (default: 600)
  • openscad_exec (str, optional): Path to OpenSCAD executable

Returns: JupyterSCAD viewer widget

SolidViewer Class

__init__(openscad_exec=None)

Initialize a SolidViewer instance.

Parameters:

  • openscad_exec (str, optional): Path to OpenSCAD executable

view(obj, width=600, height=600, cleanup=True)

Render and display a 3D object.

Parameters:

  • obj: SolidPython2 object to render
  • width (int): Viewer width in pixels
  • height (int): Viewer height in pixels
  • cleanup (bool): Whether to clean up temporary files

Returns: JupyterSCAD viewer widget

save_stl(obj, output_path, overwrite=False)

Render an object and save as STL file.

Parameters:

  • obj: SolidPython2 object to render
  • output_path (str): Path for output STL file
  • overwrite (bool): Whether to overwrite existing files

Returns: Path to saved STL file

Examples

Complex Object with Multiple Operations

from solid2 import *
from solidview import view3d

# Create a complex object
base = cube([30, 30, 5])
post = translate([15, 15, 5])(cylinder(r=3, h=20))
hole = translate([15, 15, -1])(cylinder(r=1, h=27))

final_object = base + post - hole

# View with custom dimensions
view3d(final_object, width=800, height=600)

Batch Processing

from solidview import SolidViewer
from solid2 import *

viewer = SolidViewer()

objects = []
for i in range(5):
    obj = translate([i * 15, 0, 0])(
        rotate([0, 0, i * 45])(
            cube([10, 5, 8])
        )
    )
    objects.append(obj)
  
# View each object
for i, obj in enumerate(objects):
    print(f"Object {i+1}:")
    viewer.view(obj)
  
    # Optionally save each one
    viewer.save_stl(obj, f"object_{i+1}.stl")

Troubleshooting

OpenSCAD Not Found

If you get an error about OpenSCAD not being found:

  1. Check Installation: Make sure OpenSCAD is properly installed
  2. Path Issues: On Windows, ensure OpenSCAD is in one of these locations:
    • C:\\Program Files\\OpenSCAD\\openscad.exe
    • C:\\Program Files (x86)\\OpenSCAD\\openscad.exe
  3. Manual Path: Specify the path manually:
    viewer = SolidViewer(openscad_exec="C:\\path\\to\\openscad.exe")
    

Import Errors

If you encounter import errors:

pip install solidpython2 jupyterscad

Rendering Issues

  • Memory: Large objects may require more memory
  • Complexity: Highly complex objects may take longer to render
  • Temporary Files: If cleanup fails, manually delete temp files in your system's temp directory

Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • SolidPython2 for the excellent Python → OpenSCAD interface
  • JupyterSCAD for Jupyter notebook integration
  • OpenSCAD for the powerful 3D modeling capabilities

Changelog

Version 0.1.0

  • Initial release
  • Basic 3D visualization functionality
  • Cross-platform OpenSCAD detection
  • STL export capability
  • Comprehensive documentation and examples

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

solidview-0.1.0.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

solidview-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file solidview-0.1.0.tar.gz.

File metadata

  • Download URL: solidview-0.1.0.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for solidview-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f408a46a27f86153f4f9246b32be1bcbf7cca649151b89a7ddd5e940339cc204
MD5 9f657b2cb60176b8c40e235bcfef93b1
BLAKE2b-256 06ef0e10c2b6eac4bae314bbfc4e418058cbb7565fe61d69aa616d3262db3a4b

See more details on using hashes here.

File details

Details for the file solidview-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: solidview-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for solidview-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7fb5b5b6836d35198579cdebbc60ffaa997a4e9acf6c3d0a7802044edd0a168a
MD5 44e7cd9ae4893bb239273141025ce321
BLAKE2b-256 95da562b40bf436aa815512471bc40f46d39f7f08805acfc0b56765057102630

See more details on using hashes here.

Supported by

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